/* Foldesk site. Mobile first: iPhone is the main reader. No scripts, no web fonts. */

:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #5e5e63;   /* 5.9:1 on --bg, 6.4:1 on --card */
  --accent: #2f4fcf;  /* 6.1:1 on --bg, 6.7:1 on --card */
  --line: #d2d2d7;
  --code-bg: #e8e8ed;
  /* Side padding and card insets stop growing with Dynamic Type, so large
     text keeps the screen width; on very narrow viewports they shrink to 16px. */
  --pad: max(16px, min(1.25rem, 6vw, 24px));
  --card-pad: clamp(14px, 1.125rem, 22px) clamp(16px, 1.25rem, 24px);
  --pill-x: min(0.75rem, 14px);
  --measure: 38rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;  /* 8.2:1 on --bg, 6.6:1 on --card */
    --accent: #8ea5ff; /* 9.0:1 on --bg, 7.3:1 on --card */
    --line: #38383a;
    --code-bg: #2c2c2e;
  }
}
@media (prefers-contrast: more) {
  :root { --muted: var(--text); }
}

/* Type scale in rem: 17px by default, and on iPhone and iPad it follows the
   reader's Dynamic Type text size (-webkit-touch-callout exists only there). */
html {
  font-size: 106.25%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@supports (font: -apple-system-body) and (-webkit-touch-callout: none) {
  html { font: -apple-system-body; }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

/* One reading column, with room for the notch and home indicator in landscape. */
body > header, main, body > footer {
  box-sizing: content-box;
  max-width: var(--measure);
  margin-inline: auto;
  padding-left: calc(var(--pad) + env(safe-area-inset-left, 0px));
  padding-right: calc(var(--pad) + env(safe-area-inset-right, 0px));
}
main { padding-top: 1.5rem; padding-bottom: 2.5rem; }

/* Header: brand and a two-item nav, every target at least 44 px tall. */
body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 0.75rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
}
.brand {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}
/* The nav wraps under the brand, and its pills wrap, when text is large or the
   screen is narrow. The negative start margin lines the first pill's text up
   with the brand when the nav sits on its own row. */
body > header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-width: 0;
  margin-inline-start: calc(-1 * var(--pill-x));
}
body > header nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 var(--pill-x);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
}
body > header nav a:hover { color: var(--text); }
body > header nav a:focus-visible { border-radius: 999px; }
body > header nav a:active { background: var(--card); border-color: var(--line); }
body > header nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  background: var(--card);
  border-color: var(--line);
}

/* Headings. At the default size they follow the type scale; with large
   Dynamic Type or page zoom they are capped by the screen width (as iOS grows
   titles less than body text), but never drop below the body size. */
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h1 {
  font-size: max(1.125rem, min(clamp(1.75rem, 1.2rem + 2.4vw, 2.25rem), 9vw + 0.5rem));
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}
h2 {
  font-size: max(1.0625rem, min(1.375rem, 7vw + 0.25rem));
  letter-spacing: -0.01em;
  margin: 2.25rem 0 0.5rem;
}
h3, .card h2 { font-size: max(1rem, min(1.125rem, 6vw + 0.25rem)); }
h3 { margin: 1.75rem 0 0.375rem; }
h2 + h3 { margin-top: 1rem; }

/* Body text */
p { margin: 0 0 1rem; text-wrap: pretty; }
.lead {
  font-size: max(1rem, min(1.1875rem, 6vw + 0.25rem));
  line-height: 1.45;
  color: var(--muted);
  margin: 0 0 1.5rem;
}
.meta { color: var(--muted); font-size: 0.9375rem; margin: 0 0 1.5rem; }
strong { font-weight: 600; }

a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-thickness: 2px; }
a:active { opacity: 0.6; }
/* The address and code can wrap anywhere but never get a hyphen that is not
   part of them. */
a[href^="mailto:"], code {
  overflow-wrap: anywhere;
  -webkit-hyphens: manual;
  hyphens: manual;
}

code {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  border-radius: 0.3em;
  padding: 0.1em 0.3em;
}

ul, ol { margin: 0 0 1rem; padding-left: 1.5rem; }
li { margin: 0 0 0.625rem; padding-left: 0.125rem; }
li:last-child { margin-bottom: 0; }
ol { font-variant-numeric: tabular-nums; }
li::marker { color: var(--muted); }
ol > li::marker { font-weight: 600; }

/* Body text is not hyphenated on phones: ragged-right lines read fine at 17px.
   Headings may hyphenate a long word that would otherwise break mid-letter. */
@media (max-width: 34em) {
  h1, h2 {
    -webkit-hyphens: auto;
    hyphens: auto;
    hyphenate-limit-chars: 10 4 4;
    -webkit-hyphenate-limit-before: 4;
    -webkit-hyphenate-limit-after: 4;
    -webkit-hyphenate-limit-lines: 1;
  }
}
/* Very narrow viewports (320px screens, page zoom): long words in body text
   may hyphenate, with strict limits. The footer's legal text never does. */
@media (max-width: 21em) {
  main p, main li {
    -webkit-hyphens: auto;
    hyphens: auto;
    hyphenate-limit-chars: 10 4 4;
    -webkit-hyphenate-limit-before: 4;
    -webkit-hyphenate-limit-after: 4;
    -webkit-hyphenate-limit-lines: 1;
  }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: clamp(12px, 1rem, 20px);
  padding: var(--card-pad);
  margin: 0 0 0.75rem;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card h2 { letter-spacing: 0; margin: 0 0 0.375rem; }
.card + :not(.card) { margin-top: 1.5rem; }

/* Footer */
body > footer {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
}
body > footer::before {
  content: "";
  display: block;
  border-top: 1px solid var(--line);
  margin-bottom: 0.75rem;
}
body > footer p { margin: 0.5rem 0 0; }
body > footer a { color: var(--muted); }
body > footer a:hover { color: var(--text); }
.footer-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.25rem; }
.footer-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  font-size: 0.9375rem;
}
.footer-nav a:first-child { padding-left: 0; }

/* Focus: visible for keyboard users on every link. */
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 0.375rem;
}

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

/* Wider screens: a little more air, same column. */
@media (min-width: 48em) {
  main { padding-top: 2.5rem; padding-bottom: 3.5rem; }
  body > header { padding-top: calc(1.5rem + env(safe-area-inset-top, 0px)); }
  .lead { font-size: max(1rem, min(1.25rem, 6vw + 0.25rem)); }
  .card { --card-pad: clamp(16px, 1.25rem, 24px) clamp(18px, 1.5rem, 28px); margin-bottom: 1rem; }
}
