/* ============================================================================
   Newsreader — self-hosted (Google Fonts, SIL Open Font License)

   Subset to Latin + Latin-1 + Latin Extended-A + general punctuation, both
   variable axes pinned, one cut per weight the site actually uses: 400 body,
   500 headings, 700 <strong>, italic 400 for <em> and blockquotes.
   356 KB as Google ships it -> 87 KB. Only the 20 KB regular is on the critical
   path; the rest are fetched lazily when a rule first needs them.
   ========================================================================== */

@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/newsreader-400.woff2") format("woff2");
}

@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/newsreader-500.woff2") format("woff2");
}

@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/newsreader-700.woff2") format("woff2");
}

@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/newsreader-italic-400.woff2") format("woff2");
}

/* Metric-matched fallback: the first paint sits on the same baseline grid as
   the real face, so swapping the webfont in causes no reflow. */
@font-face {
  font-family: "Newsreader Fallback";
  src: local("Times New Roman"), local("Times"), local("Liberation Serif");
  ascent-override: 69.68%;
  descent-override: 25.12%;
  line-gap-override: 0%;
  size-adjust: 105.48%;
}

/* ============================================================================
   Tokens
   ========================================================================== */

:root {
  color-scheme: light dark;

  --background: #fafafa;
  --foreground: #171717;
  --muted: #858585;
  --rule: rgb(23 23 23 / 12%);
  --note-background: rgb(0 0 0 / 5%);
  --note-text: rgb(23 23 23 / 65%);
  --selection: rgb(23 23 23 / 12%);
  /* The only colour on the site — the koi. A four-step ramp from the sumi
     markings through to where the patches catch light. */
  --koi-sumi: #3c3330;
  --koi-deep: #8f3d18;
  --koi: #b0603a;
  --koi-pale: #c98a63;

  --measure: 36rem;
  --serif: "Newsreader", "Newsreader Fallback", Times, serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #ededed;
    --muted: #b8b8b8;
    --rule: rgb(255 255 255 / 14%);
    --note-background: rgb(255 255 255 / 7%);
    --note-text: rgb(255 255 255 / 66%);
    --selection: rgb(255 255 255 / 16%);
    --koi-sumi: #b8a89f;
    --koi-deep: #e2854a;
    --koi: #cd7b4f;
    --koi-pale: #e8b190;
  }
}

/* ============================================================================
   Base
   ========================================================================== */

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
  overscroll-behavior-y: none;
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
}

::selection {
  background: var(--selection);
}

main {
  width: min(100%, var(--measure));
  margin: 0 auto;
  padding: 3rem 1rem;
}

a {
  color: var(--muted);
  text-decoration-color: currentColor;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color 140ms ease, text-decoration-color 140ms ease;
}

a:hover {
  color: var(--foreground);
  text-decoration-color: currentColor;
}

/* Inline links inside prose: underline only on hover, so a sentence with two
   links in it doesn't turn into a fence. */
a.quiet {
  text-decoration-color: transparent;
}

a.quiet:hover {
  text-decoration-color: currentColor;
}

a:focus-visible {
  color: var(--foreground);
  border-radius: 2px;
  outline: 2px solid var(--foreground);
  outline-offset: 3px;
}

/* ============================================================================
   Header — name + social links
   ========================================================================== */

.identity {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.75rem;
  row-gap: 0.6rem;
}

h1,
.site-name {
  flex: none;
  margin: 0;
  color: var(--foreground);
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.site-name {
  text-decoration-color: transparent;
}

.site-name:hover {
  text-decoration-color: currentColor;
}

nav {
  display: flex;
  flex: 1 0 auto;
  flex-wrap: nowrap;
  gap: 0.45rem;
  min-width: max-content;
  scrollbar-width: none;
}

nav::-webkit-scrollbar {
  display: none;
}

nav a {
  flex: none;
  font-size: 0.88rem;
}

/* Push the whole nav to the right edge of the measure. */
nav a:first-child {
  margin-left: auto;
}

/* ============================================================================
   Sections
   ========================================================================== */

.about {
  margin-top: 2.5rem;
}

.writings {
  margin-top: 2rem;
}

.section-title {
  margin: 0 0 0.75rem;
  color: var(--foreground);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Bulleted lists: hanging bullet on its own grid track so wrapped lines align
   to the text, not to the bullet. */
ul {
  display: grid;
  gap: 0.42rem;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.98rem;
  list-style: none;
}

li {
  display: grid;
  grid-template-columns: 0.8rem minmax(0, 1fr);
}

li::before {
  content: "\2022";
}

/* Writing index: title left, date right. */
.writing-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.writing-list li::before {
  content: none;
}

.writing-date {
  flex: none;
  font-size: 0.88rem;
  white-space: nowrap;
}

/* ============================================================================
   Koi pond — decorative ASCII animation, drawn by koi.js
   ========================================================================== */

/* Full-bleed background layer. The koi swim behind everything; main sits on
   top with its own stacking context. */
.pond {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

main {
  position: relative;
  z-index: 1;
}

.pond pre {
  margin: 0;
  font-family: var(--mono);
  /* Detail in ASCII is cell count. Small type means the koi are sampled over
     ~2.4x more cells for the same on-screen size, which is where fin rays and
     scale texture come back. */
  font-size: 7.5px;
  line-height: 1.12;
  letter-spacing: 0;
  white-space: pre;
  overflow: hidden;
  /* Water is texture, not content — don't invite a text cursor or selection. */
  user-select: none;
}

/* Held well back so body copy stays the thing you read. The koi is atmosphere;
   if you notice it before the text, the balance is wrong. */
.pond i {
  font-style: normal;
}

/* Six tonal classes, deepest to lightest. The glyph ramp gives weight; this
   gives colour, and together they're what make the body read as rounded
   rather than as a flat stencil. */
.pond .w {                      /* water and wake */
  color: var(--muted);
  opacity: 0.26;
}

.pond .k {                      /* sumi markings */
  color: var(--koi-sumi);
  opacity: 0.5;
}

.pond .d {                      /* deep red-orange, the shadowed flank */
  color: var(--koi-deep);
  opacity: 0.52;
}

.pond .a {                      /* mid orange, the bulk of the patches */
  color: var(--koi);
  opacity: 0.46;
}

.pond .p {                      /* pale orange, where the patches catch light */
  color: var(--koi-pale);
  opacity: 0.38;
}

.pond .b {                      /* mid body, between patch and belly */
  color: var(--foreground);
  opacity: 0.28;
}

.pond .l {                      /* white belly and fin membrane. Strong enough
                                   to read as part of the animal — at 0.15 the
                                   translucent tail disconnected from the body
                                   and read as grey grit. */
  color: var(--foreground);
  opacity: 0.22;
}

/* ============================================================================
   Article
   ========================================================================== */

.article {
  margin-top: 3rem;
}

.article h1 {
  margin-bottom: 0.35rem;
}

.article-date {
  display: block;
  margin-bottom: 1.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.prose {
  color: var(--muted);
  font-size: 0.98rem;
}

.prose p {
  margin: 0 0 0.9rem;
  text-wrap: pretty;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose h2,
.prose h3 {
  margin: 1.75rem 0 0.6rem;
  color: var(--foreground);
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.prose h3 {
  font-size: 1rem;
}

.prose ul,
.prose ol {
  margin: 0 0 0.9rem;
}

.prose ol {
  display: grid;
  gap: 0.42rem;
  padding: 0;
  counter-reset: item;
  list-style: none;
}

.prose ol > li {
  grid-template-columns: 1.35rem minmax(0, 1fr);
  counter-increment: item;
}

.prose ol > li::before {
  content: counter(item) ".";
  font-variant-numeric: tabular-nums;
}

.prose blockquote {
  margin: 0 0 0.9rem;
  padding-left: 0.9rem;
  border-left: 1px solid var(--rule);
  font-style: italic;
}

.prose code {
  padding: 0.1em 0.32em;
  border-radius: 3px;
  background: var(--note-background);
  font-family: var(--mono);
  font-size: 0.84em;
}

.prose pre {
  margin: 0 0 0.9rem;
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
  border-radius: 4px;
  background: var(--note-background);
  line-height: 1.5;
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: 0.82rem;
}

.prose img {
  display: block;
  width: 100%;
  height: auto;
  margin: 1.25rem 0;
}

.prose hr {
  height: 0;
  margin: 1.75rem 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

/* Boxed aside — a note, a caveat, a quoted passage. */
.note {
  margin: 0.18rem 0 0.9rem;
  padding: 0.5rem 0.7rem;
  background: var(--note-background);
  color: var(--note-text);
  font-size: 0.98rem;
  line-height: 1.45;
}

.note p {
  margin: 0;
}

.note p + p {
  margin-top: 0.35rem;
}

/* Flat list — no bullets. For books, links, anything already self-delimiting. */
.flat-list {
  gap: 0.35rem;
}

.flat-list li {
  display: block;
}

.flat-list li::before {
  content: none;
}

.item-title {
  margin: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 400;
  line-height: 1.45;
}

/* ============================================================================
   Responsive
   ========================================================================== */

@media (max-width: 22rem) {
  nav {
    flex-basis: 100%;
  }

  nav a:first-child {
    margin-left: 0;
  }
}

@media (min-width: 40rem) {
  main {
    padding: 4rem 1.5rem;
  }

  .identity {
    column-gap: 1.5rem;
  }

  nav {
    gap: 0.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  a {
    transition: none;
  }
}
