/* ------------------------------------------------------------
   Tokens
   One typeface, one accent. The green is on purpose.
------------------------------------------------------------ */
:root {
  --paper: #f5f2ea;
  --paper-2: #ece8dd;
  --ink: #1f1d1a;
  --ink-2: #3d3a34;
  --muted: #77715f;
  --rule: #dcd6c8;
  --accent: #2e6a3c;
  --accent-soft: rgba(46, 106, 60, 0.12);
  --mark: rgba(46, 106, 60, 0.16);

  --font: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --measure: 41rem;
  --gutter: clamp(16px, 5vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #131311;
    --paper-2: #1b1b18;
    --ink: #e9e5da;
    --ink-2: #c9c4b7;
    --muted: #8e8879;
    --rule: #2d2c27;
    --accent: #86c28f;
    --accent-soft: rgba(134, 194, 143, 0.12);
    --mark: rgba(134, 194, 143, 0.18);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #131311;
  --paper-2: #1b1b18;
  --ink: #e9e5da;
  --ink-2: #c9c4b7;
  --muted: #8e8879;
  --rule: #2d2c27;
  --accent: #86c28f;
  --accent-soft: rgba(134, 194, 143, 0.12);
  --mark: rgba(134, 194, 143, 0.18);
  color-scheme: dark;
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  font-feature-settings: "kern", "liga" 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}

@media (min-width: 720px) {
  body { font-size: 16.5px; }
}

::selection { background: var(--accent); color: var(--paper); }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color .15s ease, text-decoration-thickness .15s ease;
}
a:hover { color: var(--accent); text-decoration-thickness: 2px; }
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ------------------------------------------------------------
   Reading progress
------------------------------------------------------------ */
.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(0);
  z-index: 10;
}

/* ------------------------------------------------------------
   Site chrome
------------------------------------------------------------ */
.site-header,
.site-footer {
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 28px;
  padding-bottom: 28px;
  font-size: 13px;
}

.wordmark {
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.wordmark:hover { color: var(--ink); }
.wordmark .cursor {
  display: inline-block;
  width: 0.6em;
  height: 2px;
  margin-left: 2px;
  background: var(--accent);
  vertical-align: baseline;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .wordmark .cursor { animation: none; }
}


.theme-toggle {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); }

.site-footer {
  margin-top: 72px;
  padding-top: 28px;
  padding-bottom: 56px;
  background: linear-gradient(var(--rule), var(--rule)) no-repeat var(--gutter) 0 / calc(100% - var(--gutter) * 2) 1px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px 24px;
  font-size: 12.5px;
  color: var(--muted);
}
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--ink); }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}
.footer-links .to-top { color: var(--accent); }

/* ------------------------------------------------------------
   Post header
------------------------------------------------------------ */
.post {
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.post-head {
  padding: 56px 0 40px;
}

/* Cover: breaks slightly out of the text column on wide screens */
.cover {
  margin: 0 calc(50% - min(50vw - var(--gutter), 440px)) 56px;
}
.cover img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--rule);
  background: #f2efe5;
}
:root[data-theme="dark"] .cover img { filter: brightness(.88); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cover img { filter: brightness(.88); }
}

.kicker {
  margin: 0 0 28px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.kicker .tag { color: var(--accent); font-weight: 600; }
.kicker .sep { margin: 0 0.6em; opacity: .6; }

.post-title {
  margin: 0;
  font-size: clamp(30px, 6.2vw, 46px);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.dek {
  margin: 22px 0 0;
  max-width: 52ch;
  font-size: clamp(16px, 2.2vw, 18px);
  line-height: 1.6;
  font-style: italic;
  color: var(--ink-2);
  text-wrap: pretty;
}

.byline {
  margin: 32px 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}
.byline .avatar {
  flex: none;
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-2);
  box-shadow: 0 0 0 1px var(--rule);
}
.byline strong { color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------
   Prose
------------------------------------------------------------ */
.prose { counter-reset: section; }

.prose p {
  margin: 0 0 1.45em;
  text-wrap: pretty;
}

.prose em { font-style: italic; }
.prose strong { font-weight: 600; color: var(--ink); }

.prose mark {
  background: linear-gradient(transparent 58%, var(--mark) 58%);
  color: inherit;
  padding: 0 0.05em;
}

.prose .lede::first-line { font-weight: 600; }

.prose .beat {
  margin: 2.2em 0;
  padding-left: 1.2em;
  border-left: 2px solid var(--accent);
  font-weight: 500;
  color: var(--ink);
}

.prose h2 {
  counter-increment: section;
  margin: 3.4em 0 1.1em;
  font-size: 1.1em;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -0.01em;
  scroll-margin-top: 32px;
}
.prose h2::before {
  content: "§ " counter(section, decimal-leading-zero);
  display: block;
  margin-bottom: 0.35em;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--accent);
}
.prose h2 a { text-decoration: none; }
.prose h2 a:hover { color: inherit; }

/* External links get a small arrow */
.prose a[href^="http"]::after {
  content: "\2197";
  display: inline-block;
  margin-left: 0.15em;
  font-size: 0.78em;
  color: var(--accent);
  text-decoration: none;
}

/* Pull quote */
.pull {
  margin: 2.6em 0;
  padding: 0;
  border: 0;
}
.pull p {
  margin: 0 !important;
  font-size: clamp(19px, 3vw, 23px);
  line-height: 1.45;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-wrap: balance;
}
.pull p::before {
  content: "\201C";
  color: var(--accent);
  margin-right: 0.05em;
}
.pull p::after {
  content: "\201D";
  color: var(--accent);
}
.pull cite {
  display: block;
  margin-top: 0.9em;
  font-size: 12.5px;
  font-style: normal;
  color: var(--muted);
}
.pull cite::before { content: "\2014\00a0"; }

/* Definition pair (first-order / second-order) */
.orders {
  margin: 2.2em 0 2.4em;
  display: grid;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}
@media (min-width: 640px) {
  .orders { grid-template-columns: 1fr 1fr; }
}
.orders > div {
  padding: 20px 22px 22px;
  background: var(--paper);
}
.orders dt {
  margin-bottom: 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.orders dt span { color: var(--muted); font-weight: 500; }
.orders dd {
  margin: 0;
  font-size: 0.92em;
  line-height: 1.65;
  color: var(--ink-2);
}

.green { color: var(--accent); font-weight: 600; }

.small-caps-note {
  font-size: 0.86em;
  color: var(--muted);
}

/* Ending */
.coda {
  margin: 3.2em 0 0;
}
.coda p {
  margin: 0;
  font-size: clamp(20px, 3.4vw, 26px);
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.coda p em { color: var(--accent); font-style: italic; }

.signoff {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}
.signoff strong { color: var(--ink); font-weight: 600; }


/* ------------------------------------------------------------
   Home
------------------------------------------------------------ */
.home {
  max-width: calc(var(--measure) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.intro { padding: 56px 0 64px; }

.home-title {
  margin: 0;
  font-size: clamp(26px, 5vw, 38px);
  line-height: 1.18;
  font-weight: 600;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.home-title em { color: var(--accent); }

.home-dek {
  margin: 22px 0 0;
  max-width: 54ch;
  color: var(--ink-2);
  text-wrap: pretty;
}

.list-head {
  display: flex;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { border-bottom: 1px solid var(--rule); }
.post-list a {
  display: grid;
  grid-template-columns: 3ch 1fr auto;
  gap: 0 20px;
  padding: 28px 0;
  text-decoration: none;
}
.post-list .n {
  padding-top: 3px;
  font-size: 12.5px;
  color: var(--accent);
  font-weight: 500;
}
.post-list .t {
  display: block;
  font-size: 1.15em;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -0.015em;
  transition: color .2s ease;
}
.post-list .d {
  display: block;
  margin-top: 8px;
  font-size: 0.94em;
  line-height: 1.6;
  font-style: italic;
  color: var(--ink-2);
}
.post-list .m {
  display: block;
  margin-top: 12px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.post-list .go {
  padding-top: 1px;
  color: var(--muted);
  transition: transform .25s cubic-bezier(.2, .7, .2, 1), color .2s ease;
}
.post-list a:hover .t,
.post-list a:hover .go { color: var(--accent); }
.post-list a:hover .go { transform: translateX(4px); }

.more {
  margin: 20px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
}

/* ------------------------------------------------------------
   Motion
   Quiet by design: text settles in at the bottom edge and
   eases out at the top edge. The middle of the screen, where
   you actually read, stays still.
------------------------------------------------------------ */
@media (prefers-reduced-motion: no-preference) {

  /* Title block settles in once on load */
  .site-header,
  .post-head > *,
  .cover,
  .intro > *,
  .list-head,
  .post-list li,
  .more {
    animation: settle .9s cubic-bezier(.2, .7, .2, 1) both;
  }
  .site-header           { animation-delay: 0s; }
  .post-head > :nth-child(1) { animation-delay: .08s; }
  .post-head > :nth-child(2) { animation-delay: .16s; }
  .post-head > :nth-child(3) { animation-delay: .26s; }
  .post-head > :nth-child(4) { animation-delay: .36s; }
  .cover                 { animation-delay: .46s; }
  .intro > :nth-child(1) { animation-delay: .08s; }
  .intro > :nth-child(2) { animation-delay: .16s; }
  .intro > :nth-child(3) { animation-delay: .26s; }
  .intro > :nth-child(4) { animation-delay: .36s; }
  .list-head             { animation-delay: .46s; }
  .post-list li          { animation-delay: .54s; }
  .more                  { animation-delay: .64s; }

  @keyframes settle {
    from { opacity: 0; transform: translateY(10px); filter: blur(2px); }
    to   { opacity: 1; transform: none; filter: none; }
  }

  /* Scroll-linked: in at the bottom, out at the top */
  @supports (animation-timeline: view()) {
    .prose > * {
      animation: drift linear both;
      animation-timeline: view();
    }
    @keyframes drift {
      entry 0%   { opacity: 0;   transform: translateY(18px); }
      entry 90%  { opacity: 1;   transform: none; }
      exit 45%   { opacity: 1;   transform: none; }
      exit 100%  { opacity: 0.15; transform: translateY(-8px); }
    }
  }

  /* Fallback for browsers without scroll timelines (JS toggles .in) */
  .io .prose > * {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity .8s ease, transform .8s cubic-bezier(.2, .7, .2, 1);
  }
  .io .prose > .in {
    opacity: 1;
    transform: none;
  }
}
