/* Paperback background for blog posts.
   Link after a post's own stylesheets: <link rel="stylesheet" href="paper.css">.
   Only the page surface changes: body background (paper tone plus an SVG
   feTurbulence grain that scrolls with the page) and a fixed edge vignette.
   Text colors, figures, canvases, widgets, code blocks and the header keep
   their own styles. The day/night switch follows theme.js, which sets
   html[data-theme] and toggles the #night-theme stylesheet. */

html:not([data-theme="night"]) {
  --paper: #eaeae6;
  /* Whitish gray paper, a hint warm. Base tone sits a shade above #e7e7e3 so the
     paper renders at about #e7e7e3 once the grain is on. The post's --fg5 (#737373) would drop to
     4.1:1 here; one step darker keeps light-gray text above WCAG AA 4.5:1. */
  --fg5: #5f5f5f;
}
html[data-theme="night"] {
  --paper: #0f1011;
  /* The post's own night tone (#101112); the light grain lifts it to about that. */
}

html:not([data-theme="night"]) body {
  background-color: var(--paper);
  /* Two noise layers in one tile: fine grain speckle and faint horizontal
     fibers, both in a neutral gray at a few percent alpha. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .32 0 0 0 0 .31 2.2 0 0 0 -.95'/%3E%3C/filter%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.03 .55' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .4 0 0 0 0 .39 3 0 0 0 -1.55'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23g)' opacity='.12'/%3E%3Crect width='320' height='320' filter='url(%23f)' opacity='.05'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-attachment: scroll;
}

html[data-theme="night"] body {
  background-color: var(--paper);
  /* Same tile, neutral light speckle and faint fibers on the near-black. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .9 0 0 0 0 .88 2.2 0 0 0 -.95'/%3E%3C/filter%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.03 .55' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .86 0 0 0 0 .86 0 0 0 0 .84 3 0 0 0 -1.55'/%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23g)' opacity='.08'/%3E%3Crect width='320' height='320' filter='url(%23f)' opacity='.03'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-attachment: scroll;
}

/* Edge vignette: fixed to the viewport, under all content, never clickable. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 125% 110% at 50% 42%,
    rgba(70, 70, 68, 0) 60%, rgba(70, 70, 68, .05) 85%, rgba(60, 60, 58, .10) 100%);
}
html[data-theme="night"] body::before {
  background: radial-gradient(ellipse 125% 110% at 50% 42%,
    rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, .18) 85%, rgba(0, 0, 0, .30) 100%);
}

@media print {
  html:not([data-theme="night"]) body,
  html[data-theme="night"] body { background: #ffffff; }
  body::before { display: none; }
}
