/* self-hosted variable fonts, latin only */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/source-serif-4-latin.woff2") format("woff2");
}

/* fallback families with metric overrides so the swap is nearly invisible.
   Numbers from web.dev/articles/font-fallbacks / Google Fonts dev tools. */
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial");
  ascent-override: 90.49%;
  descent-override: 22.56%;
  line-gap-override: 0%;
  size-adjust: 107.4%;
}
@font-face {
  font-family: "Source Serif 4 Fallback";
  src: local("Georgia");
  ascent-override: 92%;
  descent-override: 32%;
  line-gap-override: 0%;
  size-adjust: 99%;
}

:root {
  --fg: #222220;
  --bg: #f7f4ed;
  --muted: #6c6862;
  --faint: #b4b0a6;
  --link: #1849a9;
  --visited: #1849a9;
  --rule: #e5dfd1;
  --accent: #7a2c10;
  --serif: "Source Serif 4", "Source Serif 4 Fallback", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", "Inter Fallback", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: Futura, "Trebuchet MS", Arial, sans-serif;
  font-size: 17px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e6e3dc;
    --bg: #181715;
    --muted: #9a968d;
    --faint: #4a4843;
    --link: #86b3ff;
    --visited: #86b3ff;
    --rule: #2c2a26;
    --accent: #d49774;
  }
}

/* explicit overrides from the theme toggle (win over OS preference) */
:root[data-theme="light"] {
  --fg: #222220;
  --bg: #f7f4ed;
  --muted: #6c6862;
  --faint: #b4b0a6;
  --link: #1849a9;
  --visited: #1849a9;
  --rule: #e5dfd1;
  --accent: #7a2c10;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --fg: #e6e3dc;
  --bg: #181715;
  --muted: #9a968d;
  --faint: #4a4843;
  --link: #86b3ff;
  --visited: #86b3ff;
  --rule: #2c2a26;
  --accent: #d49774;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern", "liga";
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:visited { color: var(--visited); }

/* ── sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 3.5rem;
  left: 3rem;
  width: 13.5rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  font-family: var(--sans);
  font-size: 0.86rem;
  line-height: 1.45;
}

.sidebar .brand {
  margin-bottom: 1.75rem;
}
.sidebar .brand a {
  color: var(--accent);
  text-decoration: none;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.05rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.09em;
}

.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar nav li {
  margin: 0 0 0.65rem 0;
}
.sidebar nav a {
  color: var(--link);
  text-decoration: none;
  font-family: var(--sans);
}
.sidebar nav a:visited {
  color: var(--visited);
}
.sidebar nav a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.sidebar nav a.current,
.sidebar nav a.current:visited {
  color: var(--fg);
  font-weight: 400;
  font-family: var(--sans);
}

.sidebar .meta-links {
  margin-top: 2rem;
}

.sidebar .social-links {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sidebar .social-link {
  display: inline-flex;
  width: 1.05rem;
  height: 1.05rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 80ms ease;
}

.sidebar .social-link:visited { color: var(--muted); }

.sidebar .social-link:hover,
.sidebar .social-link:visited:hover {
  color: var(--fg);
}

.sidebar .social-icon {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.sidebar .social-icon-x {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: square;
}

.sidebar .social-icon-mail {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linejoin: round;
}

.sidebar .theme {
  margin-top: 0.7rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.005em;
}
.sidebar .theme button {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  transition: color 80ms ease;
}
.sidebar .theme button:hover { color: var(--fg); }
.sidebar .theme button.active {
  color: var(--fg);
  font-weight: 600;
  cursor: default;
}
.sidebar .theme .sep {
  color: var(--faint);
  margin: 0 0.35em;
}

/* ── main / post ─────────────────────────────────────────── */
body.index main,
body.post main {
  max-width: 33rem;      /* ~561px → about 65 chars at serif body size */
  margin: 4rem 0 6rem 20rem;
  padding: 0 1.5rem;
}

.about h1 {
  font-family: var(--display);
  font-size: 1.22rem;
  font-weight: 400;
  line-height: 1.25;
  margin: 0 0 1rem 0;
  color: var(--accent);
  font-variant-caps: small-caps;
  letter-spacing: 0.02em;
}

.about p {
  margin: 0 0 1.1rem 0;
  text-wrap: pretty;
}

.post-header h1 {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.25;
  margin: 0;
  color: var(--accent);
  font-variant-caps: small-caps;
  letter-spacing: 0.08em;
  text-wrap: balance;
}

.post-header .meta {
  font-family: var(--sans);
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0.55rem 0 2.25rem 0;
  letter-spacing: 0.01em;
}

article p {
  margin: 0 0 1.1rem 0;
  hyphens: auto;
  text-wrap: pretty;
}

/* ── font comparison ───────────────────────────────────────── */
body.font-options main {
  max-width: 52rem;
  margin: 3.5rem 0 5rem 20rem;
  padding: 0 1.5rem;
}

.font-options-header h1 {
  margin: 0 0 1.5rem 0;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.font-option {
  padding: 1.2rem 0 1.35rem 0;
  border-top: 1px solid var(--rule);
}

.font-body-reference {
  padding: 0 0 1.35rem 0;
}

.font-body-copy {
  max-width: 33rem;
  margin: 0;
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.6;
}

.font-option-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0 0 0.85rem 0;
  font-family: var(--sans);
  font-size: 0.74rem;
  line-height: 1.35;
  color: var(--muted);
}

.font-option-meta code {
  font-family: var(--sans);
  color: var(--faint);
}

.font-samples {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.35rem;
}

.font-sample {
  min-width: 0;
}

.font-sample-label {
  margin: 0 0 0.45rem 0;
  font-family: var(--sans);
  font-size: 0.68rem;
  line-height: 1.3;
  color: var(--muted);
}

.font-option-brand,
.font-option h2 {
  font-family: var(--option-font);
  color: var(--accent);
  text-wrap: balance;
}

.font-option-brand {
  margin: 0 0 0.45rem 0;
  font-size: 1rem;
  line-height: 1.25;
  letter-spacing: 0.025em;
}

.font-option h2 {
  margin: 0;
  font-size: 1.22rem;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

.variant-smallcaps-regular .font-option-brand,
.variant-smallcaps-regular h2 {
  font-weight: 400;
  font-variant-caps: small-caps;
}

.variant-smallcaps-bold .font-option-brand,
.variant-smallcaps-bold h2 {
  font-weight: 700;
  font-variant-caps: small-caps;
}

.variant-normal-regular .font-option-brand,
.variant-normal-regular h2 {
  font-weight: 400;
  font-variant-caps: normal;
}

.variant-normal-bold .font-option-brand,
.variant-normal-bold h2 {
  font-weight: 700;
  font-variant-caps: normal;
}

/* ── mobile ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  :root { font-size: 16px; }
  .sidebar {
    position: static;
    width: auto;
    max-height: none;
    margin: 1.5rem 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--rule);
  }
  body.index main,
  body.post main {
    margin: 0.5rem auto 3rem;
    max-width: 100%;
    padding: 0 1.25rem;
  }
  body.font-options main {
    margin: 0.5rem auto 3rem;
    max-width: 100%;
    padding: 0 1.25rem;
  }
  .font-samples {
    grid-template-columns: 1fr;
  }
}
