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

:root {
  color-scheme: light;
  --bg: #faf7ef;
  --paper: #fffdf8;
  --ink: #201d17;
  --muted: #514a3e;
  --faint: #ede8dc;
  --rule: #bcb3a2;
  --accent: #1f562c;
  --accent-deep: #153c1f;
  --accent-soft: #e6efde;
  --serif: Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
  --sans: system-ui, -apple-system, sans-serif;
  --measure: 62ch;
  --radius: 2px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #161411;
    --paper: #211e18;
    --ink: #f7f1e7;
    --muted: #d0c5b2;
    --faint: #2c261f;
    --rule: #635847;
    --accent: #a4d9a8;
    --accent-deep: #c7edca;
    --accent-soft: #223326;
  }
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-deep); }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection { background: color-mix(in oklab, var(--accent) 25%, transparent); }

/* ----------------------------------------------------------
   Shell
   ---------------------------------------------------------- */
.shell {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 28px 64px;
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------
   Title bar (quiet rule chrome)
   ---------------------------------------------------------- */
.titlebar {
  font-family: var(--mono);
  font-size: 0.875rem;
  letter-spacing: .02em;
  color: var(--muted);
  padding: 14px 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 18px;
}
.titlebar .brand { color: var(--ink); }
.titlebar .brand b { color: var(--accent); font-weight: 500; }
.titlebar .brand a { color: inherit; }
.titlebar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
}
.titlebar nav a { color: var(--muted); }
.titlebar nav a:hover { color: var(--accent); }

/* ----------------------------------------------------------
   Masthead (index only)
   ---------------------------------------------------------- */
.masthead {
  padding: 22px 0 28px;
  border-bottom: 1px solid var(--rule);
}
.masthead .masthead-intro {
  display: flex;
  align-items: center;
  gap: 18px;
}
.masthead .masthead-intro > a { flex: none; }
.masthead .profile-photo {
  display: block;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--accent);
  background: color-mix(in oklab, var(--paper) 92%, var(--accent));
}
.masthead h1 {
  font-family: var(--serif);
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: normal;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 8px;
  text-wrap: balance;
}
.masthead .tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.125rem;
  color: var(--muted);
  max-width: 52ch;
}

/* ----------------------------------------------------------
   Post list (excerpts layout)
   ---------------------------------------------------------- */
.post-list { list-style: none; padding: 0; }
.post-list li {
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 24px;
  align-items: baseline;
}
.post-list li:last-child { border-bottom: 0; }
.post-list .date {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
  white-space: nowrap;
}
.post-list .title-line {
  font-size: 1.5rem;
  font-weight: normal;
  line-height: 1.25;
  margin-bottom: 6px;
  letter-spacing: -0.005em;
}
.post-list .title-line a { text-decoration-thickness: 1px; }
.post-list .title-line a:hover { text-decoration-thickness: 2px; }
.post-list .excerpt {
  color: var(--muted);
  font-size: 1.0625rem;
  line-height: 1.55;
  max-width: 58ch;
}

/* ----------------------------------------------------------
   Index footer
   ---------------------------------------------------------- */
.index-foot {
  margin-top: 20px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
}
.index-foot a { color: var(--muted); text-decoration: none; }
.index-foot a:hover { color: var(--accent); }

/* ----------------------------------------------------------
   Post header
   ---------------------------------------------------------- */
.post-header {
  padding: 12px 0 28px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 36px;
}
.post-header .back,
.post-foot .return-index a {
  font-family: var(--mono);
  font-size: 0.875rem;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
  display: inline-block;
  text-decoration: none;
}
.post-header .back { margin-bottom: 22px; }
.post-header .back:hover,
.post-foot .return-index a:hover { color: var(--accent); }
.post-header h1 {
  font-family: var(--serif);
  font-size: 2.5rem;
  font-weight: normal;
  line-height: 1.1;
  letter-spacing: -0.012em;
  margin-bottom: 14px;
  text-wrap: balance;
}
.post-meta {
  font-family: var(--mono);
  font-size: 0.875rem;
  letter-spacing: .04em;
  color: var(--muted);
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.post-meta a { color: var(--muted); text-decoration: underline; text-underline-offset: .12em; }
.post-meta a:hover { color: var(--accent); }

/* ----------------------------------------------------------
   Post body
   ---------------------------------------------------------- */
.post-body { max-width: var(--measure); }
.post-body > * + * { margin-top: 1.1em; }
.post-body p { font-size: 1.1875rem; line-height: 1.7; color: var(--ink); }
.post-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .11em;
}
.post-body a:hover { color: var(--accent-deep); }
.post-body h2 {
  font-family: var(--serif);
  font-size: 1.625rem;
  font-weight: normal;
  letter-spacing: -0.005em;
  margin-top: 2em;
  margin-bottom: .3em;
  color: var(--ink);
}
.post-body h2::before { content: "§ "; color: var(--accent); }
.post-body h3 {
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: normal;
  letter-spacing: -0.003em;
  margin-top: 1.6em;
  margin-bottom: .2em;
  color: var(--ink);
}
.post-body h4 {
  font-family: var(--mono);
  font-size: 0.875rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1.8em;
  margin-bottom: .2em;
}
.post-body ul,
.post-body ol {
  margin-inline-start: 1.2em;
  padding-inline-start: .2em;
}
.post-body li + li { margin-top: .45em; }
.post-body blockquote {
  border-inline-start: 2px solid var(--accent);
  padding-inline-start: 20px;
  font-style: italic;
  color: var(--muted);
  margin-inline-start: 4px;
}
.post-body figure {
  margin: 1.8em 0;
  display: grid;
  gap: .6em;
}
.post-body img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--rule);
  background: color-mix(in oklab, var(--paper) 90%, white);
}
.post-body figure img { margin: 0; }
.post-body figcaption {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
}
.post-body code {
  font-family: var(--mono);
  font-size: .88em;
  padding: 1px 6px;
  background: var(--faint);
  border-radius: var(--radius);
  color: var(--ink);
}
.post-body pre {
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.6;
  padding: 18px 20px;
  background: color-mix(in oklab, var(--ink) 6%, var(--paper));
  border-inline-start: 2px solid var(--accent);
  overflow-x: auto;
  color: var(--ink);
}
.post-body pre code { background: transparent; padding: 0; font-size: inherit; }
.post-body .table-scroll {
  max-inline-size: 100%;
  overflow-x: auto;
}
.post-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  line-height: 1.45;
  border: 1px solid var(--rule);
  background: var(--paper);
}
.post-body th,
.post-body td {
  border: 1px solid var(--rule);
  padding: 8px 10px;
  vertical-align: top;
}
.post-body th {
  background: var(--accent-soft);
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
}
.post-body td:first-child {
  background: var(--accent-soft);
}
.post-body hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2.4em auto;
  width: 140px;
}

/* Drop cap on first paragraph */
html:lang(en) .post-body > p:first-of-type::first-letter {
  font-family: var(--serif);
  font-size: 3.4em;
  line-height: 0.88;
  float: left;
  padding: .08em .08em 0 0;
  color: var(--accent);
}

/* ----------------------------------------------------------
   Post footer
   ---------------------------------------------------------- */
.post-foot {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  display: grid;
  gap: 28px;
}
.post-foot .pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  font-family: var(--mono);
  font-size: 0.875rem;
}
.post-foot .pager a {
  display: block;
  color: var(--muted);
  text-decoration: none;
}
.post-foot .pager .label {
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: 0.875rem;
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
}
.post-foot .pager .title {
  color: var(--ink);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  text-decoration: underline;
}
.post-foot .pager a:hover .title { color: var(--accent); }
.post-foot .pager .next { text-align: end; }
.post-foot .return-index {
  text-align: center;
}
.post-foot .colophon {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  padding-top: 18px;
  border-top: 1px dashed var(--rule);
}
.post-foot .colophon a { color: var(--muted); text-decoration: none; }
.post-foot .colophon a:hover { color: var(--accent); }

/* ----------------------------------------------------------
   Small screens
   ---------------------------------------------------------- */
@media (max-width: 640px) {
  .shell { padding: 0 20px 48px; }
  .titlebar nav { gap: .75rem; }
  .masthead { padding-block: 18px 24px; }
  .masthead .masthead-intro { gap: 14px; }
  .masthead .profile-photo {
    width: 62px;
    height: 62px;
  }
  .post-header h1 { font-size: 1.75rem; }
  .post-list li { grid-template-columns: minmax(0, 1fr); gap: 6px; padding-block: 18px; }
  .post-list .title-line { font-size: 1.375rem; }
  .post-foot .pager { grid-template-columns: 1fr; }
  .post-foot .pager .next { text-align: start; }
}

.skip-link {
  position: absolute;
  inset-block-start: .5rem;
  inset-inline-start: .5rem;
  z-index: 1;
  padding: .5rem .75rem;
  background: var(--paper);
  color: var(--accent-deep);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.titlebar a,
.index-foot a,
.post-header .back,
.post-foot .return-index a {
  display: inline-block;
  min-block-size: 1.5rem;
  text-decoration: underline;
}

.languages {
  --control-border: color-mix(in srgb, var(--rule), var(--muted) 35%);
  margin-block-end: 1rem;
  font: .9375rem/1.5 var(--sans);
}
.languages details {
  inline-size: fit-content;
  max-inline-size: 100%;
}
.languages summary {
  min-block-size: 2.75rem;
  padding: .55rem .75rem;
  background: var(--paper);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
}
.languages details[open] summary {
  border-end-start-radius: 0;
  border-end-end-radius: 0;
}
.languages ul {
  background: var(--paper);
  border: 1px solid var(--control-border);
  border-block-start: 0;
  border-end-start-radius: 6px;
  border-end-end-radius: 6px;
  list-style: none;
}
.languages a {
  display: block;
  padding: .45rem .75rem;
  min-block-size: 2.75rem;
}
.languages a:hover { background: var(--accent-soft); }
.languages a:focus-visible { outline-offset: -2px; }
.languages a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
}

:lang(zh-Hans) .post-body { max-width: 40ic; }
:lang(ar) .post-body pre { direction: ltr; text-align: start; }
