/* ─── Tokens ───────────────────────────────────────────────────────
   Black / white, SF Pro, soft gradients. Nothing else. */
:root {
  color-scheme: light;
  --bg:          #ffffff;
  --text:        #1d1d1f;
  --text-muted:  #6a6a6f;   /* 5.3:1 on white, 4.9:1 on the page glow */
  --rule:        rgba(0, 0, 0, 0.12);
  --nav-bg:      rgba(255, 255, 255, 0.72);
  --glow:        radial-gradient(60% 55% at 50% 0%, rgba(0, 0, 0, 0.055), transparent 70%);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;  /* code blocks only */

  --bd:         clamp(260px, 56vh, 520px);   /* where the backdrop ends */
  --bd-top:     60px;                        /* where it starts */
  --nav-h:      52px;
  --main-pt:    64px;
  --margin-col: 148px;
  --gap:        44px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #000000;
  --text:        #f5f5f7;
  --text-muted:  #86868b;   /* 6:1 on black */
  --rule:        rgba(255, 255, 255, 0.16);
  --nav-bg:      rgba(0, 0, 0, 0.7);
  --glow:        radial-gradient(60% 55% at 50% 0%, rgba(255, 255, 255, 0.10), transparent 70%);
}

/* ─── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;  /* stop iOS inflating text when rotated */
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;  /* iOS: ignore the collapsing address bar */
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.35s ease, color 0.35s ease;
}

/* ambient gradient, fixed behind everything */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--glow);
  pointer-events: none;
  z-index: 0;
}
.nav, .main { position: relative; z-index: 1; }

::selection { background: var(--text); color: var(--bg); }

a { color: inherit; }

button { font: inherit; color: inherit; }

/* keyboard focus */
:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 4px;
}

/* accessibility helpers */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip {
  position: absolute;
  left: 16px; top: -64px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  text-decoration: none;
  transition: top 0.2s ease;
}
.skip:focus { top: 12px; }

/* ─── Page frame ─────────────────────────────────────────────────── */
.page {
  max-width: 940px;
  margin: 0 auto;
  padding-left: 32px;
  padding-right: 32px;
}

/* the signature layout: a narrow margin column + a text column */
.row {
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  column-gap: var(--gap);
}

.margin {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.7;
  letter-spacing: -0.003em;
  color: var(--text-muted);
  padding-top: 0.55em;
}

/* ─── Nav ────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid transparent;
  transition: background-color 0.35s ease, border-color 0.3s ease;
}
.nav.scrolled { border-bottom-color: var(--rule); }

.nav-inner {
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  column-gap: var(--gap);
  align-items: center;
  height: var(--nav-h);
}

.nav-logo {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

.nav-links {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 28px;
  font-size: 13px;
  letter-spacing: -0.003em;
}

.nav-links a,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}
.nav-links a[aria-current="page"] { color: var(--text); }

.nav-links li:last-child { margin-left: auto; }

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  letter-spacing: inherit;
  padding: 0;
}

/* ─── Main ───────────────────────────────────────────────────────── */
.main { padding-top: var(--main-pt); padding-bottom: 120px; }

/* ─── Home: status ───────────────────────────────────────────────── */
.hero { height: calc(var(--bd) - var(--nav-h) - var(--main-pt)); margin-bottom: 24px; }

.status {
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
}

/* ─── Backdrop: Monte Baldo ∩ Fitz Roy, full-bleed behind the top of the home page ─ */
.backdrop {
  position: absolute;
  top: var(--bd-top); left: 0; right: 0;
  height: calc(var(--bd) - var(--bd-top));
  pointer-events: none;
  z-index: 0;
  color: var(--text);
  animation: reveal 2.4s cubic-bezier(.22, .61, .36, 1) both;
}
@keyframes reveal {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}
.backdrop svg { display: block; width: 100%; height: 100%; overflow: visible; }
.backdrop path { vector-effect: non-scaling-stroke; }
.backdrop .front { fill: none; stroke-width: 1.4; stroke-linejoin: round; opacity: 0.85; }
.backdrop .baldo { fill: none; stroke-width: 1.1; stroke-linejoin: round; opacity: 0.5; }

/* ─── Home: intro ────────────────────────────────────────────────── */
.intro { margin-bottom: 96px; }

.intro-text {
  font-size: 19px;
  line-height: 1.6;
  letter-spacing: -0.012em;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-wrap: pretty;
}

/* ─── Sections ───────────────────────────────────────────────────── */
.section { margin-bottom: 96px; }

/* ─── Index (post list) ──────────────────────────────────────────── */
.post-list { list-style: none; }

.post-item { border-top: 1px solid var(--rule); }
.post-list > .post-item:last-child { border-bottom: 1px solid var(--rule); }

.post-item a {
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  column-gap: var(--gap);
  padding: 24px 0;
  text-decoration: none;
}

.post-no {
  font-size: 13px;
  color: var(--text-muted);
  padding-top: 0.55em;
}

.post-item-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.post-title {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  transition: opacity 0.2s ease;
}

.post-date {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.post-excerpt {
  margin-top: 6px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 36em;
}

.view-all {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  transition: opacity 0.2s ease;
}
.view-all { gap: 6px; }
.view-all::after { content: "›"; }

/* on the home page the list sits inside the text column, label in the margin */
.row .post-item a { grid-template-columns: 1fr; }
.row .post-no { display: none; }

/* optical alignment of margin labels with the first line beside them (desktop only) */
@media (min-width: 721px) {
  #about-label     { padding-top: 4px; }
  #writing-label   { padding-top: 27px; }
  #elsewhere-label { padding-top: 11px; }
}

/* ─── Writing page header ────────────────────────────────────────── */
.page-header { margin-bottom: 72px; }
.page-header .margin { align-self: end; padding-bottom: 0.9em; }

.page-title {
  font-weight: 600;
  font-size: clamp(44px, 7vw, 72px);
  letter-spacing: -0.045em;
  line-height: 1;
}

/* ─── Single post ────────────────────────────────────────────────── */
.post-heading {
  font-weight: 600;
  font-size: clamp(34px, 5.4vw, 54px);
  line-height: 1.06;
  letter-spacing: -0.04em;
  text-wrap: balance;
  margin-bottom: 52px;
}

.post-margin-block + .post-margin-block { margin-top: 12px; }
.post-margin-block span,
.post-margin-block time { display: block; color: var(--text); font-weight: 400; }

.post-body { max-width: 34em; }

.post-body p {
  font-size: 19px;
  line-height: 1.65;
  letter-spacing: -0.012em;
  margin-bottom: 1.3em;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  text-wrap: pretty;
}
.post-body p:last-child { margin-bottom: 0; }

.post-body a {
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--text-muted);
}

.post-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 56px;
  font-size: 14px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

/* markdown content */
.post-body h2, .post-body h3, .post-body h4 {
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin: 2.2em 0 0.7em;
}
.post-body h2 { font-size: 28px; }
.post-body h3 { font-size: 22px; }
.post-body h4 { font-size: 18px; }
.post-body > :first-child { margin-top: 0; }

.post-body ul, .post-body ol { margin: 0 0 1.3em 1.3em; font-size: 19px; line-height: 1.65; letter-spacing: -0.012em; }
.post-body li { margin-bottom: 0.4em; padding-left: 0.2em; }
.post-body li::marker { color: var(--text-muted); }

.post-body blockquote {
  margin: 0 0 1.3em;
  padding-left: 22px;
  border-left: 1px solid var(--text-muted);
  color: var(--text-muted);
}
.post-body blockquote p { margin-bottom: 0.8em; }

.post-body strong { font-weight: 600; }

.post-body code {
  font-family: var(--mono);
  font-size: 0.82em;
  padding: 0.12em 0.4em;
  border-radius: 5px;
  background: var(--rule);
}
.post-body pre {
  margin: 0 0 1.5em;
  padding: 18px 20px;
  overflow-x: auto;
  border-radius: 12px;
  background: var(--rule);
  font-size: 14px;
  line-height: 1.6;
}
.post-body pre code { padding: 0; background: none; font-size: inherit; }

.post-body hr { border: none; border-top: 1px solid var(--rule); margin: 2.4em 0; }

.post-body figure { margin: 2em 0; }
.post-body img { display: block; max-width: 100%; height: auto; border-radius: 12px; }
.post-body figcaption { margin-top: 10px; font-size: 13px; color: var(--text-muted); }

/* ─── Contact ────────────────────────────────────────────────────── */
.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0 28px;
  font-size: 14px;
}
.contact-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

/* ─── Tags ───────────────────────────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: 0 10px; }
.tag { font-size: 13px; color: var(--text-muted); }

/* ─── Utility ────────────────────────────────────────────────────── */
.empty {
  font-size: 14px;
  color: var(--text-muted);
  padding: 24px 0;
  list-style: none;
}

.lead {
  margin-top: 28px;
  font-size: 19px;
  letter-spacing: -0.012em;
}
.lead a { text-underline-offset: 3px; text-decoration-thickness: 1px; }

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root { --margin-col: 0px; --gap: 0px; }

  .page { padding-left: 22px; padding-right: 22px; }
  :root { --nav-h: 48px; --main-pt: 56px; }

  .nav-inner { display: flex; align-items: center; gap: 22px; }
  .nav-links { flex: 1; gap: 22px; }
  .nav-links li:first-child { display: none; }  /* the logo is the home link */

  .main { padding-bottom: 88px; }

  /* margin column collapses into a label above the content */
  .row, .post-item a { grid-template-columns: 1fr; }
  .margin { padding-top: 0; margin-bottom: 10px; }
  .post-no { display: none; }

  .intro { margin-bottom: 72px; }
  .section { margin-bottom: 72px; }
  .intro-text, .post-body p, .post-body ul, .post-body ol { font-size: 17px; }
  .post-body h2 { font-size: 24px; }
  .post-title { font-size: 19px; }
  .post-heading { margin-bottom: 32px; }
  .post-meta-margin { margin-bottom: 28px; }
  .post-meta-margin { display: flex; flex-wrap: wrap; gap: 4px 18px; }
  .post-meta-margin .post-margin-block { margin: 0 !important; }
  .post-item-header { flex-direction: column; gap: 2px; }
  .page-header .margin { padding-bottom: 0; }
}

/* hover effects only where there is a real pointer (avoids sticky hover on touch) */
@media (hover: hover) {
  .nav-links a:hover { color: var(--text); }
  .nav-logo:hover { opacity: 0.6; }
  .theme-toggle:hover { color: var(--text); }
  .post-item a:hover .post-title { opacity: 0.55; }
  .view-all:hover { opacity: 0.55; }
  .post-body a:hover { text-decoration-color: var(--text); }
  .post-back:hover { color: var(--text); }
  .contact-links a:hover { opacity: 0.55; }
}

/* print: just the words */
@media print {
  :root { --bg: #fff; --text: #000; --text-muted: #444; --rule: rgba(0, 0, 0, 0.25); }
  body::before, .backdrop, .nav, .skip, .theme-toggle, .post-back, .view-all { display: none !important; }
  .main { padding: 0; }
  .post-body a::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #444; }
  .post-body p, .post-body li { orphans: 3; widows: 3; }
}

/* portrait phones: the status line can run two lines wide, so the mountains
   start below it instead of behind it, and get a little taller to compensate */
@media (max-width: 720px) and (orientation: portrait) {
  :root { --bd: clamp(380px, 62vh, 560px); --bd-top: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .backdrop { animation: none; }
  body, .nav, .skip { transition: none; }
}
