/* ---------------------------------------------------------------------------
   Tokens. Light palette on bare :root, dark redefined in two guarded places so
   the toggle wins in both directions and "system" still resolves correctly.
--------------------------------------------------------------------------- */
:root {
  --bg: #fbfaf8;
  --bg-raised: #ffffff;
  --bg-sunken: #f1efeb;
  --ink: #16191d;
  --ink-soft: #4d545d;
  --ink-faint: #7a828c;
  --rule: #e0ddd6;
  --rule-strong: #cfcbc2;
  --accent: #1a5fb4;
  --accent-soft: #e8f0fb;
  --warm: #b06000;
  --shadow: 0 1px 2px rgba(20, 22, 26, .05), 0 8px 24px rgba(20, 22, 26, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --wrap: 68rem;
  --measure: 38rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --bg-raised: #171b21;
    --bg-sunken: #0a0c0f;
    --ink: #e8e9eb;
    --ink-soft: #b0b6be;
    --ink-faint: #838b95;
    --rule: #262c34;
    --rule-strong: #384049;
    --accent: #6db3ff;
    --accent-soft: #16232f;
    --warm: #f0a04b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --bg-raised: #171b21;
  --bg-sunken: #0a0c0f;
  --ink: #e8e9eb;
  --ink-soft: #b0b6be;
  --ink-faint: #838b95;
  --rule: #262c34;
  --rule-strong: #384049;
  --accent: #6db3ff;
  --accent-soft: #16232f;
  --warm: #f0a04b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

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

/* The `hidden` attribute must beat any display rule set by a class below,
   or a hidden form keeps rendering because `display: grid` outranks the UA
   stylesheet. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

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

img { max-width: 100%; height: auto; display: block; border-radius: 8px; }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 50;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* --- header ------------------------------------------------------------- */
.site-head {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.head-inner { display: flex; align-items: center; gap: 1.25rem; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 650; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg), 0 0 0 3px var(--accent-soft);
}
.nav { margin-left: auto; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.nav a { color: var(--ink-soft); text-decoration: none; font-size: .95rem; padding: .2rem 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Narrow screens: brand and toggle on one line, nav on its own line below,
   rather than letting four links reflow into a ragged two-row block. */
@media (max-width: 34rem) {
  .head-inner { flex-wrap: wrap; gap: .35rem 1rem; padding-block: .5rem; }
  .brand-text { white-space: nowrap; }
  .nav { order: 3; width: 100%; margin-left: 0; gap: 1.1rem; flex-wrap: nowrap; overflow-x: auto; }
  .theme-toggle { margin-left: auto; }
  .hero { padding: 2.75rem 0 2.25rem; }
}

.theme-toggle {
  border: 1px solid var(--rule-strong); background: var(--bg-raised);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; padding: 0; flex: none;
}
.theme-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: linear-gradient(90deg, var(--ink) 0 50%, transparent 50% 100%);
  border: 1.5px solid var(--ink);
}

/* --- hero --------------------------------------------------------------- */
.hero { padding: 4.5rem 0 3rem; border-bottom: 1px solid var(--rule); }
.hero h1 {
  font-family: var(--serif); font-weight: 600; letter-spacing: -.02em;
  font-size: clamp(2.3rem, 6vw, 3.6rem); line-height: 1.08; margin: 0 0 1rem;
}
.hero .lede { font-size: clamp(1.05rem, 2.4vw, 1.3rem); color: var(--ink-soft); max-width: var(--measure); margin: 0 0 1.75rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; }

.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1.1rem; border-radius: 999px; font-size: .95rem; font-weight: 550;
  text-decoration: none; border: 1px solid transparent; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--rule-strong); color: var(--ink); background: var(--bg-raised); }
.btn-ghost:hover { border-color: var(--ink-faint); }

/* --- sections ----------------------------------------------------------- */
.section { padding: 3.25rem 0; }
.section + .section { border-top: 1px solid var(--rule); }
.section-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1.75rem; }
.section-head h2 { font-family: var(--serif); font-weight: 600; font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
.section-head .more { margin-left: auto; font-size: .92rem; }

.eyebrow {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); font-weight: 600; margin: 0 0 .5rem;
}

/* --- project cards ------------------------------------------------------ */
.card-grid { display: grid; gap: 1.1rem; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.card {
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px;
  padding: 1.25rem; display: flex; flex-direction: column; gap: .55rem;
  box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--rule-strong); }
.card h3 { margin: 0; font-size: 1.12rem; line-height: 1.3; font-weight: 600; }
.card h3 a { color: var(--ink); text-decoration: none; }
.card h3 a:hover { color: var(--accent); }
.card p { margin: 0; color: var(--ink-soft); font-size: .94rem; }
.card-meta { margin-top: auto; padding-top: .6rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .8rem; color: var(--ink-faint); }

.tag {
  font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  padding: .15rem .5rem; border-radius: 999px; text-decoration: none;
}
.tag.status-draft { background: color-mix(in srgb, var(--warm) 15%, transparent); color: var(--warm); }
.tag.status-local { background: var(--bg-sunken); color: var(--ink-faint); }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }
.filters button {
  font: inherit; font-size: .85rem; cursor: pointer;
  border: 1px solid var(--rule-strong); background: var(--bg-raised); color: var(--ink-soft);
  border-radius: 999px; padding: .3rem .85rem;
}
.filters button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- article ------------------------------------------------------------ */
.article-head { padding: 3rem 0 1.5rem; border-bottom: 1px solid var(--rule); }
.article-head h1 {
  font-family: var(--serif); font-weight: 600; letter-spacing: -.02em;
  font-size: clamp(2rem, 5vw, 3rem); line-height: 1.12; margin: .35rem 0 .75rem;
}
.article-head .lede { color: var(--ink-soft); font-size: 1.12rem; max-width: var(--measure); margin: 0 0 1rem; }
.article-meta { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; font-size: .85rem; color: var(--ink-faint); }

.article-layout { display: grid; gap: 2.5rem; grid-template-columns: minmax(0, 1fr); padding: 2rem 0 3rem; }
@media (min-width: 62rem) {
  .article-layout { grid-template-columns: minmax(0, 1fr) 15rem; }
  .toc { position: sticky; top: 5rem; align-self: start; }
}
.toc { font-size: .88rem; border-left: 2px solid var(--rule); padding-left: 1rem; }
.toc p { margin: 0 0 .5rem; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; }
.toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.toc a { color: var(--ink-soft); text-decoration: none; }
.toc a:hover, .toc a.active { color: var(--accent); }
.toc .lvl-3 { padding-left: .85rem; }

.prose { max-width: var(--measure); }
.prose > * + * { margin-top: 1.15rem; }
.prose h2 { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; margin-top: 2.4rem; letter-spacing: -.01em; scroll-margin-top: 5rem; }
.prose h3 { font-size: 1.15rem; font-weight: 650; margin-top: 1.9rem; scroll-margin-top: 5rem; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li + li { margin-top: .35rem; }
.prose blockquote {
  margin: 1.5rem 0; padding: .25rem 0 .25rem 1.1rem;
  border-left: 3px solid var(--warm); color: var(--ink-soft); font-style: italic;
}
.prose code { font-family: var(--mono); font-size: .87em; background: var(--bg-sunken); padding: .12em .35em; border-radius: 4px; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
.prose img { margin-block: 1.5rem; border: 1px solid var(--rule); }

.code-block { position: relative; margin: 1.5rem 0; }
.code-block pre {
  margin: 0; overflow-x: auto; background: var(--bg-sunken);
  border: 1px solid var(--rule); border-radius: 10px; padding: 1rem 1.1rem;
}
.code-block code { font-family: var(--mono); font-size: .84rem; line-height: 1.6; background: none; padding: 0; }
.code-lang {
  position: absolute; top: .5rem; right: .6rem; font-family: var(--mono);
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint);
}
.copy-code {
  position: absolute; top: .45rem; right: .45rem; font: inherit; font-size: .72rem;
  padding: .2rem .55rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--rule-strong); background: var(--bg-raised); color: var(--ink-soft);
  opacity: 0; transition: opacity .15s ease;
}
.code-block:hover .copy-code, .copy-code:focus-visible { opacity: 1; }
.code-block:hover .code-lang { opacity: 0; }

/* --- callouts ----------------------------------------------------------- */
.note {
  border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  background: var(--bg-raised); border-radius: 0 10px 10px 0; padding: 1rem 1.15rem;
}
.note.warm { border-left-color: var(--warm); }
.note p { margin: 0; }
.note p + p { margin-top: .6rem; }

/* --- support / tips ----------------------------------------------------- */
.tier-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.tier {
  background: var(--bg-raised); border: 1px solid var(--rule); border-radius: 12px;
  padding: 1.3rem; box-shadow: var(--shadow);
}
.tier .amount { font-family: var(--serif); font-size: 2rem; line-height: 1; display: block; margin-bottom: .35rem; }
.tier .label { font-weight: 600; display: block; margin-bottom: .4rem; }
.tier p { margin: 0; color: var(--ink-soft); font-size: .92rem; }

/* --- comments ----------------------------------------------------------- */
.comments { border-top: 1px solid var(--rule); padding: 2.5rem 0 3.5rem; }
.comments h2 { font-family: var(--serif); font-size: 1.45rem; margin: 0 0 .35rem; font-weight: 600; }
.comments .count { color: var(--ink-faint); font-size: .9rem; margin: 0 0 1.5rem; }
.comment-form { display: grid; gap: .75rem; max-width: var(--measure); margin-bottom: 2rem; }
.field { display: grid; gap: .3rem; }
.field label { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field textarea {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--bg-raised);
  border: 1px solid var(--rule-strong); border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
.field textarea { min-height: 7rem; resize: vertical; }
.form-row { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); }
.form-foot { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.form-note { font-size: .82rem; color: var(--ink-faint); margin: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.comment-list { display: grid; gap: 1rem; max-width: var(--measure); list-style: none; padding: 0; margin: 0; }
.comment {
  background: var(--bg-raised); border: 1px solid var(--rule);
  border-radius: 10px; padding: 1rem 1.15rem;
}
.comment header { display: flex; gap: .6rem; align-items: baseline; margin-bottom: .4rem; }
.comment .who { font-weight: 600; font-size: .95rem; }
.comment .when { font-size: .8rem; color: var(--ink-faint); }
.comment .badge { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--warm); }
.comment p { margin: 0; color: var(--ink-soft); white-space: pre-wrap; }

.status {
  font-size: .88rem; border-radius: 8px; padding: .7rem .9rem;
  border: 1px solid var(--rule); background: var(--bg-raised); color: var(--ink-soft);
  max-width: var(--measure);
}
.status[data-kind="error"] { border-color: color-mix(in srgb, var(--warm) 50%, var(--rule)); }
.status[data-kind="ok"] { border-color: color-mix(in srgb, var(--accent) 50%, var(--rule)); }
.status[hidden] { display: none; }

/* --- footer ------------------------------------------------------------- */
.site-foot { border-top: 1px solid var(--rule); background: var(--bg-sunken); padding: 2.5rem 0; margin-top: 2rem; }
.foot-inner { display: grid; gap: .6rem; }
.foot-name { font-weight: 600; margin: 0; }
.foot-links { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .92rem; }
.foot-fine { margin: 0; color: var(--ink-faint); font-size: .85rem; }

.empty { color: var(--ink-faint); font-style: italic; }

/* --- auth ---------------------------------------------------------------- */
.whoami { font-size: .9rem; color: var(--ink-faint); margin: 0 0 .75rem; }
.badge-account { color: var(--accent); }
.cf-turnstile { margin: .25rem 0; min-height: 65px; }
[data-signin] .filters { margin-bottom: 1.5rem; }
[data-signin] .comment-form, [data-signin] .note { max-width: var(--measure); }
[data-admin] .comment .form-foot { margin-top: .75rem; }
[data-admin] .comment-list { max-width: 46rem; }
[data-admin] label.form-note { display: flex; align-items: center; gap: .4rem; margin: 0 0 1rem; }
.signin-note { margin-top: 2rem; }
