/* Fonts are subset (Inter 400–600 and JetBrains Mono): Basic Latin, Latin-1
   (å ä ö é ü …), typographic quotes and dashes, bullet, ellipsis and arrows.
   scripts/build.mjs refuses posts with other characters. File names change
   when the files change, since /fonts/* is cached for a year. */
@font-face {
  font-family: "Inter";
  src: url("/fonts/inter-v4.woff2") format("woff2");
  font-weight: 400 600;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-v2.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
/* Metric-matched fallback, so nothing jumps when Inter arrives. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Roboto");
  ascent-override: 90.2%;
  descent-override: 22.48%;
  line-gap-override: 0%;
  size-adjust: 107.4%;
}

/* ---- Theme tokens ----------------------------------------------------------- */
:root {
  --bg: #121212;
  --fg: #ececec;
  --muted: #a8a8a8;
  --status: #9a9a9a;
  --faint: #8c8c8c;
  --line: #262626;
  --hover: #1c1c1c;
  --accent: #ececec;             /* monochrome: same tone as the PH */
  /* Hidden PH (main.js). Drawn once in light glyphs; the light theme flips it
     with a CSS filter, so a theme change never needs a repaint. */
  --ph-base: 0.055;               /* resting opacity, desktop */
  --ph-base-touch: 0.09;          /* phones: smaller glyphs, needs more */
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

/* Light counterpart: same structure, contrast checked (text >= 4.5:1 on --bg). */
:root[data-theme="light"] {
  --bg: #f6f6f3;
  --fg: #151515;
  --muted: #555555;
  --status: #5e5e5e;
  --faint: #6b6b6b;
  --line: #e1e1dc;
  --hover: #ebebe6;
  --accent: #151515;
  color-scheme: light;
}

/* Theme switch: one GPU cross-fade of the whole page (View Transitions). */
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 180ms; animation-timing-function: ease-out; }

/* ---- Base -------------------------------------------------------------------- */
* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--fg); }

body {
  font-family: "Inter", "Inter Fallback", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Layout ------------------------------------------------------------------ */
.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding:
    max(48px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(48px, env(safe-area-inset-bottom))
    max(clamp(24px, 9vw, 140px), env(safe-area-inset-left));
}

.intro {
  flex: 1 1 420px;
  max-width: clamp(480px, 30vw, 600px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ---- Status line ----------------------------------------------------------- */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--status);
}
.loader { color: var(--accent); display: inline-block; width: 1ch; text-align: center; }

/* ---- Name and pitch ------------------------------------------------------- */
h1 {
  margin: 0;
  font-size: clamp(40px, 3.2vw, 56px);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.bio {
  margin: -16px 0 0;
  font-size: clamp(17px, 1.2vw, 20px);
  line-height: 1.6;
  color: var(--muted);
}

.build {
  color: var(--fg);
  font-family: var(--mono);
  /* Shrinks on narrow screens so the longest phrase (25ch) stays on
     one line and the links below never jump when it changes. */
  font-size: min(0.95em, calc((100vw - 112px) / 15.6));
  white-space: nowrap;
}

/* ---- Links ------------------------------------------------------------------- */
.links {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 52px;
  padding: 0 18px;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  text-decoration: none;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  transition: background 120ms ease;
}
.row[hidden] { display: none; }
.row:last-child { border-bottom: 0; }
/* Focus ring follows the card's corners instead of being clipped by them. */
.row:first-child { border-radius: 11px 11px 0 0; }
.row:last-child { border-radius: 0 0 11px 11px; }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.row:active { background: var(--hover); }
@media (hover: hover) {
  .row:hover { background: var(--hover); }
  .row:hover .icon { color: var(--fg); }
}

.label { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.hint {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
}
.row.copied .hint { color: var(--accent); }
.row.manual .label { user-select: text; -webkit-user-select: text; cursor: text; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  color: var(--faint);
  stroke: currentColor;            /* follows forced-colors / high contrast */
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 120ms ease;
}
.row:focus-visible .icon { color: var(--fg); }
.row.copied .icon { color: var(--accent); }

/* ---- 404 ----------------------------------------------------------------------- */
.back {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--faint);
  text-decoration: none;
}
.back:hover, .back:focus-visible { color: var(--fg); }

/* ---- Hidden PH (drawn in main.js) ----------------------------------------- */
#field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
/* Light theme: invert the canvas, so light glyphs become dark ones instantly. */
:root[data-theme="light"] #field { filter: invert(1); }

/* ---- Theme switch, top-right corner -------------------------------------- */
.theme-toggle {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--faint);
  cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
/* Shows the theme you'd switch to: sun in dark, moon in light. */
.theme-toggle .moon { display: none; }
:root[data-theme="light"] .theme-toggle .moon { display: block; }
:root[data-theme="light"] .theme-toggle .sun { display: none; }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) { .theme-toggle:hover { color: var(--fg); background: var(--hover); } }

/* ---- Phones -------------------------------------------------------------------- */
@media (max-width: 760px) {
  .page {
    align-items: flex-end;
    padding-left: max(24px, env(safe-area-inset-left));
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }
  /* One line for the name down to 320px (304px of text at 34px). */
  h1 { font-size: clamp(28px, 8.6vw, 34px); }
}

/* Landscape phones: tighter, so Email stays on screen. */
@media (max-height: 480px) and (orientation: landscape) {
  .page { align-items: center; padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .intro { gap: 18px; }
  .row { min-height: 44px; }
}

/* ---- Posts: list on the home page ------------------------------------------- */
.posts { display: flex; flex-direction: column; gap: 10px; }
.posts-label {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 400;
  color: var(--status);
}
.post-row { align-items: center; padding-top: 12px; padding-bottom: 12px; }
.post-row .label { line-height: 1.4; }
.post-row time { flex: none; }

/* ---- Posts: reading pages ---------------------------------------------------- */
.post-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(88px, env(safe-area-inset-top))
    max(24px, env(safe-area-inset-right))
    max(64px, env(safe-area-inset-bottom))
    max(clamp(24px, 9vw, 140px), env(safe-area-inset-left));
}
/* Breadcrumb: "home" goes straight to the start page. Links get a 44px tap height. */
.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -12px 0 -12px -10px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--status);
}
.crumbs a, .crumbs [aria-current] {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--status);
  text-decoration: none;
}
.crumbs [aria-current] { padding-left: 0; }
.crumbs a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) { .crumbs a:hover { color: var(--fg); background: var(--hover); } }
.crumbs a:active { background: var(--hover); }

.post { max-width: 40rem; display: flex; flex-direction: column; gap: 28px; }
.post-head { display: flex; flex-direction: column; gap: 12px; }
.post-head h1 { font-size: clamp(28px, 3vw, 38px); line-height: 1.15; overflow-wrap: break-word; }
.post-meta { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--status); }
.dek { margin: 0; font-size: 18px; line-height: 1.55; color: var(--muted); }

.prose {
  font-size: 17px;
  line-height: 1.65;
  color: var(--fg);
  overflow-wrap: break-word;
}
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote { margin: 0 0 1.1em; }
.prose h2 { margin: 1.8em 0 0.6em; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.prose h3 { margin: 1.5em 0 0.5em; font-size: 18px; font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin: 0.3em 0; }
.prose strong { font-weight: 600; }
.prose a { color: var(--fg); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.prose a:hover { text-decoration-thickness: 2px; }
.prose code { font-family: var(--mono); font-size: 0.88em; }
.prose pre {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.5;
}
.prose pre code { font-size: 14px; }
.prose blockquote { margin-left: 0; padding-left: 16px; border-left: 2px solid var(--line); border-radius: 0; color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

@media (min-width: 1100px) {
  .prose { font-size: 18px; }
}
