/* =========================================================================
   faisal.nyc — "Speed Yellow"
   Design: Porsche Speedgelb as the identity + interaction color, held over a
   quiet warm-paper canvas with near-black ink — the Marco.org reading
   discipline (huge legible serif, generous air, a single confident accent),
   given a louder, more design-literate voice.

   Type:  Space Grotesk (display) · Newsreader (body) · JetBrains Mono (code)
   ========================================================================= */

:root {
  color-scheme: light;

  /* --- Core canvas --- */
  --paper: #fbfaf6;          /* warm off-white, not clinical white */
  --paper-raised: #f4f1e8;   /* faint warm panel */
  --ink: #16140d;            /* warm near-black */
  --ink-soft: #3a362b;       /* body-adjacent */
  --muted: #6b6555;          /* metadata, captions */
  --rule: #e7e1cf;           /* hairline rules */
  --rule-strong: #d8d0b7;

  /* --- Speed Yellow system (Porsche Speedgelb family) --- */
  --speed: #f4d000;          /* primary */
  --speed-bright: #ffdf1f;   /* hover / glow */
  --speed-deep: #b8950a;     /* yellow text on light (AA-safe accent) */
  --speed-ink: #2a2100;      /* ink to sit ON yellow */

  /* --- Complement: desaturated blue-violet (yellow's true opposite) --- */
  --violet: #2e2a4a;         /* visited / secondary structure */
  --violet-soft: #5b5680;
  --violet-tint: #ecebf4;

  /* --- Effects --- */
  --shadow: 0 18px 48px rgba(28, 24, 8, 0.14);
  --shadow-soft: 0 8px 26px rgba(28, 24, 8, 0.10);

  /* --- Type --- */
  --display: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;
  --body: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 38rem;          /* reading column */
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  font-size: 19px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

#top { scroll-margin-top: 0; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--body);
  font-optical-sizing: auto;
  line-height: 1.66;
  font-size: 1.06rem;
  /* subtle warm vignette so the page feels like paper, not a screen */
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(244, 208, 0, 0.06), transparent 60%);
  background-repeat: no-repeat;
}

::selection {
  background: var(--speed);
  color: var(--speed-ink);
}

/* ---------------------------------------------------------------- Links */
a {
  color: var(--ink);
  text-decoration: none;
  background-image: linear-gradient(var(--speed), var(--speed));
  background-repeat: no-repeat;
  background-position: 0 88%;
  background-size: 100% 0.18em;   /* the yellow "marker" underline */
  transition: background-size 0.18s ease, color 0.18s ease;
}

a:hover,
a:focus-visible {
  color: var(--ink);
  background-size: 100% 0.95em;   /* fills like a highlighter on hover */
  background-position: 0 80%;
}

.post-body a:visited { color: var(--violet); }

/* ------------------------------------------------ Layout & containers */
.site-header,
main {
  width: min(var(--measure), calc(100% - 2.6rem));
  margin-inline: auto;
}

main { padding-bottom: 3.5rem; }

/* ----------------------------------------------------------- Masthead */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem 1.4rem;
  padding: 3.2rem 0 1.6rem;
  margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--rule-strong);
}

.site-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
  background-image: linear-gradient(var(--speed), var(--speed));
  background-repeat: no-repeat;
  background-position: 0 98%;
  background-size: 100% 0.12em;
  transition: background-size 0.18s ease;
}

.site-title:hover,
.site-title:focus-visible {
  background-size: 100% 0.35em;
}

nav {
  display: flex;
  align-items: center;
  gap: 1.3rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-title::before {
  /* small speed-yellow dot mark, the new subtle wordmark cue */
  content: "";
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.5rem;
  vertical-align: 0.12em;
  background: var(--speed);
  border-radius: 50%;
}

nav a {
  color: var(--muted);
  background-size: 100% 0.1em;
  background-position: 0 100%;
  padding-bottom: 0.15em;
}

nav a:hover,
nav a:focus-visible,
nav a[aria-current="page"] {
  color: var(--ink);
  background-size: 100% 0.55em;
}

.masthead-return {
  position: fixed;
  top: calc(0.7rem + env(safe-area-inset-top));
  left: calc(0.7rem + env(safe-area-inset-left));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  width: 3.05rem;
  height: 2.3rem;
  border: 1px solid rgba(22, 20, 13, 0.08);
  border-radius: 999px;
  background: rgba(251, 250, 246, 0.86);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1.72rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.9;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-0.4rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.masthead-return::before {
  content: "";
  position: absolute;
  top: 0.45rem;
  left: 0.74rem;
  width: 0.36rem;
  height: 0.36rem;
  background: var(--speed);
  border-radius: 50%;
}

.masthead-return::after {
  content: "";
  position: absolute;
  left: 0.82rem;
  right: 0.82rem;
  bottom: 0.36rem;
  height: 0.16rem;
  border-radius: 999px;
  background: var(--speed);
}

.masthead-return span {
  position: relative;
  z-index: 1;
  transform: translateY(0.05rem);
}

.masthead-return:hover,
.masthead-return:focus-visible {
  color: var(--ink);
  background: rgba(251, 250, 246, 0.96);
}

.is-scrolled-deep .masthead-return {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ----------------------------------------------------------- Headings */
h1, h2, h3 {
  font-family: var(--display);
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.12;
  font-weight: 560;
}

.post-header h1,
.archive h1,
.photos-header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.65rem, 1.1rem + 2.4vw, 2.35rem);
}

.post-header h1 a {
  color: var(--ink);
  background-size: 100% 0;          /* title links stay clean until hover */
}

.post-header h1 a:hover,
.post-header h1 a:focus-visible {
  background-size: 100% 0.14em;
  background-position: 0 92%;
}

.post-body h2 { font-size: 1.5rem; margin: 2.2rem 0 0.6rem; }
.post-body h3 { font-size: 1.2rem; margin: 1.8rem 0 0.5rem; }

/* --------------------------------------------------------------- Time */
time {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-style: normal;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ----------------------------------------------------- Post / stream */
.post {
  padding: 1.6rem 0 1.7rem;
  border-bottom: 1px solid var(--rule);
}
.post:last-of-type { border-bottom: none; }

/* Contain any floated media (e.g. an image with float:left/right) inside its
   own post so it can never bleed into the next post in the stream. */
.post,
.post-body { display: flow-root; }

/* the title carries enough presence on its own; trim the leading space its
   large grotesk line-box adds above the first line */
.stream-post .post-header h1,
.single-post .post-header h1 { margin-top: 0; }

.single-post,
.page,
.archive,
.photos-page,
.photo-detail { padding: 0.6rem 0 2.8rem; }

.page h1,
.not-found h1 {
  margin: 0 0 1.2rem;
  font-size: clamp(1.65rem, 1.1rem + 2.4vw, 2.35rem);
}

.post-body {
  margin-top: 1.4rem;
  /* Anchor the reading typography on the body container itself so that
     content authored as loose HTML (e.g. MarsEdit posts, which may emit bare
     text, <div>, or <span> blocks rather than Markdown <p> paragraphs)
     renders in the same Newsreader serif and rhythm as the migrated Markdown
     posts. Without this, text that escapes a <p> wrapper falls back to the
     wrong inherited styling and looks like a different font. */
  font-family: var(--body);
  font-size: 1.06rem;
  line-height: 1.66;
  color: var(--ink-soft);
}

/* Force every text-bearing descendant of the post body to the reading serif,
   regardless of how the source HTML wrapped it. Headings, code, and the
   back-to-top mark keep their own families via the more specific rules below. */
.post-body p,
.post-body div,
.post-body span,
.post-body li,
.post-body blockquote {
  font-family: var(--body);
}

/* MarsEdit often groups paragraphs as <div> blocks; give them paragraph
   spacing so they read like the Markdown posts rather than colliding. */
.post-body > div { margin: 0 0 1.25rem; }
.post-body > div:last-child { margin-bottom: 0; }

.post-body > p:first-of-type {
  /* a gentle lede: slightly larger opening paragraph */
  font-size: 1.12rem;
  color: var(--ink-soft);
}

.post-body p,
.post-body blockquote,
.post-body figure,
.post-body ul,
.post-body ol,
.post-body pre {
  margin: 0 0 1.25rem;
}

.post-body ul,
.post-body ol { padding-left: 1.3rem; }
.post-body li { margin-bottom: 0.4rem; }

/* --------------------------------------------------------- Blockquote */
blockquote {
  margin-inline: 0;
  padding: 0.1rem 0 0.1rem 1.3rem;
  border-left: 3px solid var(--speed);
  color: var(--muted);
  font-family: var(--body);
  font-size: 0.9rem;
  font-style: normal;
  line-height: 1.55;
}

blockquote p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------- Code */
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--violet-tint);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  background: var(--ink);
  color: #f4f1e8;
  padding: 1.1rem 1.2rem;
  border-radius: 8px;
  border-left: 4px solid var(--speed);
  overflow-x: auto;
}
pre code { background: none; padding: 0; color: inherit; }

/* --------------------------------------------------------------- Media */
img { max-width: 100%; height: auto; }

figure { margin-inline: 0; }

.feature-image {
  margin: 1.6rem 0 1.8rem;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  position: relative;
}

.feature-image::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 4px;
  background: var(--speed);
}

.feature-image img {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: cover;
}

.image-text-link {
  display: inline;
  cursor: zoom-in;
}

/* ----------------------------------------------------------- Lightbox */
.has-image-lightbox { overflow: hidden; }

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1.8rem;
  -webkit-tap-highlight-color: transparent;
  background: rgba(22, 20, 13, 0.86);
  backdrop-filter: blur(3px);
}

.image-lightbox-frame {
  /* Fill the viewport so a clicked image opens genuinely full-size (up to its
     native resolution) rather than being capped smaller than the inline view. */
  width: 100%;
  max-width: 100%;
  max-height: calc(100vh - 3.5rem);
  margin: 0;
  display: grid;
  gap: 0.6rem;
}

.image-lightbox-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 7.5rem);
  margin-inline: auto;
  /* Clicking the image is a control (close/toggle), not content selection —
     suppress the selection/blue-flash and the mobile tap-highlight overlay. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* Clicking inside the lightbox is a control, never content. Kill selection
   tint, tap-highlight, drag, and the mouse-click :focus/:active flash so a
   click reads as a clean toggle (keyboard :focus-visible rings preserved). */
.image-lightbox,
.image-lightbox * {
  -webkit-tap-highlight-color: transparent;
}
.image-lightbox ::selection { background: transparent; }
.image-lightbox img,
.image-lightbox a,
.image-lightbox figure,
.image-lightbox figcaption {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.image-lightbox img:focus,
.image-lightbox a:focus:not(:focus-visible),
.image-lightbox figure:focus {
  outline: none;
}

.image-lightbox-frame figcaption {
  color: #f4f1e8;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.4;
  text-align: center;
}

.image-lightbox-frame figcaption a {
  color: var(--speed-bright);
  background: none;
}

.image-lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 2.3rem;
  height: 2.3rem;
  border: none;
  border-radius: 50%;
  background: var(--speed);
  color: var(--speed-ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: 2px 2px 0 #000;
  transition: transform 0.12s ease;
  outline: none;
}
.image-lightbox-close:hover,
.image-lightbox-close:focus-visible {
  transform: translate(-1px, -1px);
  background: var(--speed-bright);
}
/* Replace the browser-default blue focus ring (which framed the whole photo on
   open, since the close button is auto-focused) with a subtle on-theme ring. */
.image-lightbox-close:focus-visible {
  box-shadow: 2px 2px 0 #000, 0 0 0 3px rgba(244, 208, 0, 0.55);
}

/* -------------------------------------------------------- Footnotes */
.footnote-ref,
.footnote-ref-link {
  position: relative;
  top: -0.4em;                 /* lift cleanly without inflating line box */
  font-family: var(--mono);
  font-size: 0.66em;
  font-weight: 600;
  line-height: 0;
  color: var(--speed-deep);
  background: none;
  vertical-align: baseline;
}

.footnote-ref-link {
  margin-left: 0.12em;
  padding: 0.1em 0.32em;
  border-radius: 4px;
  background: var(--violet-tint);
  color: var(--violet);
}

.footnote-ref-link:hover,
.footnote-ref-link:focus-visible {
  background: var(--speed);
  color: var(--speed-ink);
}

.footnote-popover {
  position: absolute;
  z-index: 20;
  max-width: calc(100vw - 1.8rem);
  box-sizing: border-box;
  padding: 0.85rem 1rem 0.9rem;
  border: 1px solid var(--rule-strong);
  border-top: 4px solid var(--speed);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.5;
}

.footnote-popover[aria-hidden="true"] { display: none; }
.footnote-popover p,
.footnote-popover ol,
.footnote-popover ul { margin: 0; }
.footnote-popover a,
.footnotes a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.footnotes-sep {
  width: 2.2rem;
  margin: 1.8rem 0 0.9rem;
  border: none;
  border-top: 2px solid var(--speed);
}

.footnotes {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
}

.footnotes-list {
  margin: 0;
  padding-left: 1.4rem;
}

/* the footnotes section is the last child of .post-body: kill its trailing
   margin so it doesn't stack with the article's bottom padding */
.post-body > .footnotes:last-child,
.post-body > .footnotes:last-child .footnotes-list,
.post-body > .footnotes:last-child .footnote-item:last-child,
.post-body > .footnotes:last-child .footnote-item:last-child p {
  margin-bottom: 0;
}

.footnote-item {
  margin: 0 0 0.3rem;
  padding-left: 0.2rem;
}

.footnote-item::marker {
  color: var(--speed-deep);
}

.footnote-item p {
  margin: 0;
  overflow-wrap: anywhere;
}

.footnote-backref {
  margin-left: 0.3em;
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
}

.footnote-backref:hover,
.footnote-backref:focus-visible {
  color: var(--ink);
  background: none;
}

.post-footer {
  margin-top: 1.8rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

.post-top-link {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
}

.post-top-link-ico {
  flex: 0 0 auto;
  font-style: normal;
  line-height: 1;
}

.post-top-link:hover,
.post-top-link:focus-visible {
  color: var(--ink);
  background: none;
}

/* ----------------------------------------------------------- Archive */
.archive h1 { margin-bottom: 1.4rem; }

.archive ol {
  list-style: none;
  padding: 0;
  margin: 1.6rem 0 0;
}

.archive li {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  align-items: baseline;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule);
}

.archive li time { font-size: 0.7rem; }

.archive li a {
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--ink);
  background-size: 100% 0;
}
.archive li a:hover,
.archive li a:focus-visible {
  background-size: 100% 0.55em;
}

/* ----------------------------------------------------------- Photos */
.photos-page {
  width: calc(100vw - 1rem);
  margin-left: calc(50% - 50vw + 0.5rem);
  padding-top: 0;
}

.photos-header {
  margin: 0;
}

.photos-header p,
.photos-note {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.98rem;
}

/* Option B grid: fills left-to-right, row by row (true reading order),
   preserves each photo's aspect ratio (no crop). Rows are not height-aligned
   by design — ragged bottoms are the tradeoff for keeping originals uncropped. */
/* No-JS fallback: CSS grid, left-to-right, no crop (mixed aspect ratios leave
   some gaps). With JS, photos-masonry.js sets .is-masonry and absolutely
   positions cards into the shortest column -> left-to-right order, tight pack,
   no white space, no cropping. */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin-top: 0;
  align-items: start;
}

.photo-grid.is-masonry {
  display: block;
  position: relative;
}

.photo-card {
  display: block;
  margin: 0;
}

.photo-link {
  position: relative;
  display: block;
  background: none;
  overflow: hidden;
}

.photo-link:hover,
.photo-link:focus-visible {
  background: none;
}

.photo-link img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.22s ease, filter 0.22s ease;
}

.photo-link:hover img,
.photo-link:focus-visible img {
  transform: scale(1.018);
  filter: saturate(0.96) brightness(0.82);
}

.photo-overlay {
  position: absolute;
  inset: auto 0 0;
  display: grid;
  gap: 0.25rem;
  padding: 3rem 0.8rem 0.75rem;
  color: #fff;
  font-family: var(--display);
  font-size: 0.82rem;
  font-weight: 560;
  line-height: 1.18;
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.45);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.64), rgba(0, 0, 0, 0));
  opacity: 0;
  transform: translateY(0.35rem);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.photo-overlay time {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.56rem;
}

.photo-link:hover .photo-overlay,
.photo-link:focus-visible .photo-overlay {
  opacity: 1;
  transform: translateY(0);
}

/* Detail page escapes the narrow --measure reading column so a photo can fill
   a large viewport. Widen ONLY the detail-page <main> (not the grid page, which
   does its own full-bleed breakout), so .photo-detail centers within it. */
main:has(.photo-detail) {
  width: min(1200px, calc(100% - 2.6rem));
}

.photo-detail {
  width: 100%;
  margin-inline: auto;
}

.photo-detail figure {
  margin: 0;
}

/* The zoom wrapper must stay block-level despite the global .image-text-link
   rule (which forces display:inline for inline text image links). */
.photo-detail-zoom,
.photo-detail-zoom.image-text-link {
  display: block;
  background: none;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.photo-detail-zoom img {
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

/* No mouse-click focus/active flash on the stage-2 photo (keyboard users still
   get a :focus-visible ring on the link). */
.photo-detail-zoom:focus:not(:focus-visible) {
  outline: none;
}
.photo-detail-zoom img::selection { background: transparent; }

.photo-detail-zoom:hover,
.photo-detail-zoom:focus-visible {
  background: none;
}

/* Photo page = three rows: masthead, photo, caption. The masthead and the
   caption take the space their content needs; the photo row takes ALL the
   rest, and the photo fills that row as fully as its shape allows — never
   cropped, never scrolled. The browser's own layout does this for any screen
   or window size; nothing is measured. */
body.photos-shell:has(.photo-detail) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
/* The masthead keeps its usual spacing, or a small share of the screen's
   height when that is smaller — on short screens the spacing gives way to the
   photo. The wordmark, links and type never change. */
body.photos-shell:has(.photo-detail) .site-header {
  padding-top: min(3.2rem, 6vh);
  padding-bottom: min(1.6rem, 3vh);
  margin-bottom: min(1.6rem, 3vh);
}
@supports (height: 100dvh) {
  body.photos-shell:has(.photo-detail) .site-header {
    padding-top: min(3.2rem, 6dvh);
    padding-bottom: min(1.6rem, 3dvh);
    margin-bottom: min(1.6rem, 3dvh);
  }
}
body.photos-shell:has(.photo-detail) main {
  /* Side margins taper smoothly to nothing on narrow screens (no jump). */
  width: min(1200px, calc(100% - 2 * clamp(0rem, 4vw - 1rem, 1.3rem)));
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 0.8rem; /* same breathing room as between photo and caption */
}
/* The photo-and-caption area: everything below the masthead. */
.photo-detail {
  flex: 1 1 auto;
  min-height: 0;
  container-type: size;
  padding-bottom: 0;
}
/* The caption is a two-line block (title, then date) under the photo; the
   photo takes the rest of the area, as large as its shape allows. */
.photo-detail figure {
  --caption-block: calc(0.8rem + 0.98rem * 1.66 + 0.35rem + 0.72rem * 1.66);
  margin: 0 auto;
  max-width: 100%;
}
.photo-detail figure.has-dims {
  width: min(100cqw, calc((100cqh - var(--caption-block)) * var(--pw) / var(--ph)));
  /* Never taller than the area: if a long caption needs an extra line, the
     photo gives up that line (shown whole inside its box), not the screen. */
  max-height: 100cqh;
  display: flex;
  flex-direction: column;
}
.photo-detail figure.has-dims .photo-detail-zoom {
  position: relative;
  flex: 0 1 auto;
  min-height: 0;
  width: 100%;
  aspect-ratio: var(--pw) / var(--ph);
}
/* Pinned to its frame so every browser shrinks it with the frame. */
.photo-detail figure.has-dims img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.photo-detail figure.has-dims figcaption { flex: none; }
.photo-heading:focus { outline: none; }
.photo-detail img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.photo-detail figcaption {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.98rem;
}

/* "All photos" on the left (back toward the gallery); the photo's caption and
   date stacked and right-aligned on the right. */
.photo-detail figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  row-gap: 0.5rem;
  box-sizing: border-box;
  /* Lines up with the photo, but never narrower than a comfortable reading
     width (then it extends evenly on both sides of a narrow photo). */
  --cap-w: max(100%, min(26rem, 100cqw));
  width: var(--cap-w);
  margin-inline: calc((100% - var(--cap-w)) / 2);
}
.photo-info {
  flex: 1 1 11rem;
  display: grid;
  gap: 0.35rem;
  justify-items: end;
  text-align: right;
  min-width: 0;
}
.photo-back {
  flex: none;
  color: var(--muted);
  background: none;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease;
}
.photo-back:hover,
.photo-back:focus-visible {
  color: var(--ink);
  background: none;
}

/* Swipe surface: allow vertical page scroll, we handle horizontal. */
.photo-detail { touch-action: pan-y pinch-zoom; }

/* ------------------------------------------------------- Photo viewer */
/* Whole photo, fitted, on near-black. Click to zoom toward a spot; the image
   pans with the mouse (or by dragging on touch). No scrollbars, no frame. */
.has-photo-viewer { overflow: hidden; }

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: transparent;
  cursor: zoom-out;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@keyframes photo-viewer-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Near-black backdrop; fades in/out and with a swipe-down. */
.photo-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: #0c0c0b;
  opacity: 0;
  pointer-events: none;
}

/* Layer 0: the photo and all its gestures. */
.photo-viewer-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
}

/* The photo's pose: open/close travel and swipe-down drag. */
.photo-viewer-frame {
  position: relative;
  transform-origin: 50% 50%;
  will-change: transform;
  pointer-events: none;
}

/* Zoom and pan only. */
.photo-viewer-img {
  pointer-events: none;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  transform-origin: 50% 50%;
  will-change: transform;
  -webkit-user-drag: none;
}
.photo-viewer.is-zoomed,
.photo-viewer.is-zoomed .photo-viewer-stage { cursor: zoom-out; }

.photo-viewer:focus { outline: none; }

/* Controls bar: revealed by a single tap/click (or mouse movement), fades
   after a few seconds. "‹ Back" left, caption + date right — mirrors the
   photo page's caption row. */
/* Layer 1: controls. */
.photo-viewer-bar {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 4.5rem max(1.25rem, env(safe-area-inset-right)) max(1.6rem, calc(env(safe-area-inset-bottom) + 0.9rem)) max(1.25rem, env(safe-area-inset-left));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
  color: rgba(255, 255, 255, 0.88);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.photo-viewer.show-controls .photo-viewer-bar { opacity: 1; }

.photo-viewer.controls-live .photo-viewer-back { pointer-events: auto; }

.photo-viewer-back {
  flex: none;
  margin: -0.9rem; /* bigger tap target, same look */
  padding: 0.9rem;
  border: 0;
  background: none;
  color: inherit;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.photo-viewer-back:hover { color: #fff; }
.photo-viewer-back:focus { outline: none; }
.photo-viewer-back:focus-visible { outline: 1px solid rgba(255, 255, 255, 0.6); outline-offset: 2px; }

.photo-viewer-info {
  display: grid;
  gap: 0.3rem;
  justify-items: end;
  min-width: 0;
  text-align: right;
}
.photo-viewer-info > span {
  font-family: var(--body);
  font-size: 1.02rem;
  line-height: 1.25;
}
.photo-viewer-info time {
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  .photo-viewer-bar { transition: none; }
}

/* ----------------------------------------------------- Back to top */
/* A continuous blog never shows a footer. Instead, each article ends with a
   small inline up-arrow sitting right after the final sentence's period,
   styled to match the footnote reference glyph: "...lastword. ↑" */
.to-top {
  /* return-arrow end-mark mirroring the footnote jump-to-top arrow: plain
     inline text sitting on the same baseline as the preceding sentence. */
  margin-left: 0.18em;
  color: var(--speed-deep);
  background: none;
  text-decoration: none;
  transition: color 0.16s ease;
  /* keep the glyph on the text baseline rather than letting the emoji
     variation lift it; this is the alignment fix from earlier feedback. */
  vertical-align: baseline;
  font-size: 0.9em;
  line-height: inherit;
}

.to-top-ico {
  font-style: normal;
  font-variant-emoji: text;
  vertical-align: baseline;
}

.to-top:hover,
.to-top:focus-visible {
  color: var(--ink);
  background: none;
}

/* ------------------------------------------------------ Responsive */
@media (max-width: 560px) {
  html { font-size: 18px; }

  .footnote-popover {
    position: fixed;
    left: max(0.85rem, env(safe-area-inset-left));
    right: max(0.85rem, env(safe-area-inset-right));
    bottom: calc(0.85rem + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    max-width: none;
    max-height: min(42vh, 18rem);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 100;
    font-size: 0.82rem;
    line-height: 1.45;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding-top: 2.4rem;
  }

  nav { gap: 1rem; }

  .archive li {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
  }

  .photo-card { margin: 0; }

  .image-lightbox { padding: 1rem; }
}

@media (max-width: 700px) {
  body.photos-shell {
    background: #fff;
    background-image: none;
  }

  body.photos-shell main {
    width: 100%;
    padding: 0 0 1.2rem;
  }

  body.photos-shell .photos-page {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  body.photos-shell .photo-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.28rem;
  }

  body.photos-shell .photo-card {
    margin: 0;
  }

  body.photos-shell .photo-link img {
    width: 100%;
  }

  body.photos-shell .photo-overlay {
    display: none;
  }

  /* Edge-to-edge photo on phones, but keep the caption row off the screen edge. */
  body.photos-shell .photo-detail figcaption {
    /* 1rem when the photo runs edge to edge; 0 when it's narrower than the
       screen (tall photos), so the caption lines up with the photo's edges.
       (% padding resolves against the figure's width.) */
    padding-inline: max(0px, calc(1rem - (100vw - 100%) / 2));
    gap: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
