/* Design tokens (palette, type, accents) live in one shared file so the blog
   and the full-bleed story pages stay visually in sync. @import must be first. */
@import url("/static/tokens.css");

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 1.5vw + 0.6rem, 19px);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.5rem) clamp(1rem, 4vw, 1.5rem);
  /* No own background. The soft-edge backdrop is painted by ::before
     (declared in the effects section) so the cream tint fades smoothly
     into the effect at the edges instead of cutting at a hard line. */
}

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

.site {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}
.site-title {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
  font-size: 1.05em;
}
.site .rss {
  font-size: 0.85em;
  color: var(--muted);
  text-decoration: none;
}
.site .rss:hover { color: var(--link); }

.site-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85em;
  color: var(--muted);
}
.site-footer a {
  text-decoration: none;
  color: var(--muted);
}
.site-footer a:hover { color: var(--link); }

.header-right { display: inline-flex; align-items: baseline; gap: 0.6rem; }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.05em 0.4em;
  color: var(--muted);
  font: inherit;
  font-size: 0.9em;
  line-height: 1.2;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--link); border-color: var(--link); }

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.post-list li {
  display: flex;
  gap: 1rem;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--rule);
  align-items: center;
}
.post-list time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85em;
  flex: 0 0 auto;
}
.post-list a {
  text-decoration: none;
  color: var(--fg);
}
.post-list a:hover { color: var(--link); text-decoration: underline; }
.post-list .empty { color: var(--muted); display: block; }

article h1 {
  font-size: 1.6em;
  line-height: 1.2;
  margin: 0 0 0.25rem;
}
article .meta {
  color: var(--muted);
  font-size: 0.85em;
  margin: 0 0 1.25rem;
}
article .tldr {
  font-family: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-style: normal;
  font-weight: 500;
  font-size: 1.15em;
  color: var(--fg);
  margin: 0.25rem 0 2rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
}
article .body p { margin: 0 0 1em; }
article .body h2 { font-size: 1.2em; margin: 1.5em 0 0.4em; }
article .body h3 { font-size: 1.05em; margin: 1.4em 0 0.3em; }
article .body code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.92em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
article .body pre {
  background: var(--code-bg);
  padding: 0.75rem 1rem;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 0.9em;
}
article .body pre code { background: transparent; padding: 0; }
article .body blockquote {
  margin: 1em 0;
  padding: 0.1em 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}
article .body img { max-width: 100%; height: auto; }

/* Tags: small chips shown next to the date on a post / on the index. */
.tags { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; }
.meta .tags { margin-left: 0.6rem; vertical-align: baseline; }
.index-tags { margin-left: 0.4rem; }
.tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78em;
  color: var(--muted);
  background: var(--code-bg);
  padding: 0.05em 0.4em;
  border-radius: 3px;
  text-decoration: none;
}
a.tag:hover { color: var(--link); }
.tag-filter {
  font-size: 0.9em;
  color: var(--muted);
  margin: 0 0 1rem;
}

/* Landing page */
body.landing main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
body.landing h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  margin: 0 0 1rem;
}
body.landing .links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
body.landing .intro {
  margin: 0 0 1.8rem;
  color: var(--muted);
  max-width: 34ch;
  line-height: 1.5;
}
body.landing .links {
  gap: 0.7rem;
}
body.landing .links li {
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
}
body.landing .links a {
  font-size: 1.1em;
  min-width: 6rem;
}
body.landing .links .note {
  color: var(--muted);
  font-size: 0.74em;
  letter-spacing: 0.02em;
}

/* ================================================================
   Background effects: four pastel layers cross-fade on a 240s loop.
   Anchored to the top-right corner via a radial mask so the effect
   sits at the edges and doesn't push behind the reading column.
   ================================================================ */

.fx-stack {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  /* No mask: effect fills the full viewport. The semi-transparent
     backdrop on `main` is what keeps the reading column calmer. */
}
main { position: relative; z-index: 1; }

/* Soft-edge backdrop behind `main`. Sized 16rem larger than `main` in
   every direction so the elliptical tint can fade over a generous
   distance instead of stopping at `main`'s box. Uses relative-colour
   syntax to get a semi-transparent version of --bg without darkening it
   (which `color-mix(... , transparent)` would do via premultiplication). */
main::before {
  content: "";
  position: absolute;
  inset: -16rem;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    ellipse closest-side at center,
    rgb(from var(--bg) r g b / 0.82) 30%,
    rgb(from var(--bg) r g b / 0) 100%
  );
}

@media (max-width: 640px) {
  /* Keep the effect on phones but drop the expensive bits:
     - stripes layer uses mix-blend-mode:difference + background-attachment:
       fixed, both costly on mobile GPUs. Hide it entirely.
     - conic's filter animation (hue-rotate every frame) forces a repaint
       60 fps. Replace with a static filter at lower blur.
     - other layers keep their position/opacity animations (cheap) but
       use smaller blur radii. */
  .fx-stripes { display: none; }
  .fx-conic {
    animation: fx-cycle 240s linear infinite;
    animation-delay: -180s;
    filter: blur(40px) saturate(130%);
  }
  .fx-mesh     { filter: blur(25px) saturate(130%); }
  .fx-diagonal { filter: blur(35px) saturate(130%); }
}

/* Recolor the effect in dark mode. The pastel layers were tuned for the
   cream background; opacity alone keeps the same light-pink hue, just
   faint. Applying brightness < 1 actually drives the colours toward the
   dark end (light pink → deep mauve), and saturate > 1 keeps them from
   going grey. Explicit-theme selectors come after the media query and
   outweigh it by specificity, so the toggle still wins. */
@media (prefers-color-scheme: dark) {
  .fx-stack { opacity: 0.5; filter: brightness(0.3) saturate(1.25); }
}
:root[data-theme="light"] .fx-stack { opacity: 1; filter: none; }
:root[data-theme="dark"]  .fx-stack { opacity: 0.5; filter: brightness(0.3) saturate(1.25); }

.fx-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
}

/* Cross-fade keyframes. Cycle is 240s (4min); each layer visible for
   90s with ~30s fade in and ~30s fade out. Layers are offset by 60s
   via animation-delay so during the 30s overlap two adjacent layers
   blend. Peak opacity 0.7, not 1, so they don't fully dominate. */
@keyframes fx-cycle {
  0%     { opacity: 0; }
  12.5%  { opacity: 0.85; }
  25%    { opacity: 0.85; }
  37.5%  { opacity: 0; }
  100%   { opacity: 0; }
}

/* Layer 1: pastel stripes (originally fx-2) */
.fx-stripes {
  --s: repeating-linear-gradient(100deg, #fff 0%, #fff 7%, transparent 10%, transparent 12%, #fff 16%);
  --r: repeating-linear-gradient(100deg, #ffb6c1 10%, #d4f5d4 15%, #d4f5d4 20%, #aed6ff 25%, #d6c6ff 30%);
  background-image: var(--s), var(--r);
  background-size: 300%, 200%;
  filter: blur(12px) invert() saturate(0.85);
  animation: fx-cycle 240s linear infinite;
  animation-delay: 0s;
}
.fx-stripes::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--s), var(--r);
  background-size: 200%, 100%;
  mix-blend-mode: difference;
  animation: fx-stripe-pan 90s linear infinite reverse;
}
@keyframes fx-stripe-pan {
  from { background-position: 50% 50%; }
  to   { background-position: 350% 350%; }
}

/* Layer 2: pastel conic (originally fx-6) */
.fx-conic {
  background: conic-gradient(from 0deg at 80% 20%, #ffd6e0, #d4f5d4, #d6e8ff, #e0d6ff, #ffeebf, #ffd6e0);
  animation: fx-cycle 240s linear infinite, fx-hue 70s linear infinite;
  animation-delay: -180s, 0s;
}
@keyframes fx-hue {
  from { filter: blur(80px) saturate(140%) hue-rotate(0deg); }
  to   { filter: blur(80px) saturate(140%) hue-rotate(360deg); }
}

/* Layer 3: pastel mesh (originally fx-10) */
.fx-mesh {
  background:
    radial-gradient(circle at 25% 20%, #ffd6e0 0%, transparent 35%),
    radial-gradient(circle at 75% 30%, #d4f5d4 0%, transparent 35%),
    radial-gradient(circle at 60% 80%, #d6e8ff 0%, transparent 35%),
    radial-gradient(circle at 30% 70%, #e0d6ff 0%, transparent 35%);
  background-size: 150% 150%, 130% 130%, 140% 140%, 160% 160%;
  filter: blur(50px);
  animation: fx-cycle 240s linear infinite, fx-mesh-drift 40s ease-in-out infinite alternate;
  animation-delay: -120s, 0s;
}
@keyframes fx-mesh-drift {
  from { background-position: 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: 10% -10%, -10% 5%, 5% 10%, -5% -5%; }
}

/* Layer 4: pastel diagonal (originally fx-14) */
.fx-diagonal {
  background-image: repeating-linear-gradient(45deg, #ffd6e0 0%, #d4f5d4 12%, #d6e8ff 24%, #e0d6ff 36%, #ffeebf 48%, #ffd6e0 60%);
  background-size: 250% 250%;
  filter: blur(70px);
  animation: fx-cycle 240s linear infinite, fx-diag-pan 35s linear infinite;
  animation-delay: -60s, 0s;
}
@keyframes fx-diag-pan {
  from { background-position: 0 0; }
  to   { background-position: 250% 250%; }
}
