/*
  Dracula Paper

  A sheet of paper on a desk at night, lit by one lamp above the top right
  corner. One column of book type on the sheet; the site name and its links
  sit on the desk. Colours are Dracula Classic (draculatheme.com/spec).
  No script and no web fonts.
*/

:root {
  color-scheme: dark;

  /* Dracula Classic */
  --background: #282a36;
  --background-dark: #21222c;
  --background-darker: #191a21;
  --selection: #44475a;
  --foreground: #f8f8f2;
  --comment: #6272a4;
  --red: #ff5555;
  --orange: #ffb86c;
  --yellow: #f1fa8c;
  --green: #50fa7b;
  --cyan: #8be9fd;
  --purple: #bd93f9;
  --pink: #ff79c6;

  /* The job of each colour on this page */
  --desk: var(--background-darker);
  --desk-ink: var(--yellow);
  --desk-ink-soft: color-mix(in srgb, var(--yellow) 55%, var(--desk));
  --desk-rule: var(--selection);
  --lamp: color-mix(in srgb, var(--comment) 26%, transparent);
  --sheet: var(--background);
  --ink: var(--foreground);
  --ink-soft: color-mix(in srgb, var(--foreground) 68%, var(--sheet));
  --rule: var(--selection);
  --well: var(--background-dark);
  --label: var(--purple);
  --initial: var(--pink);
  --link: var(--cyan);
  --quote: var(--yellow);

  /* Type */
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: "Helvetica Neue", Arial, sans-serif;
  --mono: Menlo, Consolas, "DejaVu Sans Mono", monospace;

  /* Widths */
  --desk-width: 1160px;
  --sheet-width: 920px;
  --measure: 680px;

  /*
    Paper grain. Each layer is an SVG turbulence filter. The colour matrix
    turns one noise channel into the alpha of a flat white or black fill.
  */
  --grain-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 .55 0 0 0 -.25'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --grain-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.7' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 -.4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --mottle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='g' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.006' numOctaves='3' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .7 0 0 0 -.3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

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

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

/* ---------- The desk ---------- */

body {
  margin: 0;
  min-height: 100vh;
  padding-block: 0 72px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background-color: var(--desk);
  background-image: var(--grain-light), var(--grain-dark);
  background-size: 200px, 260px;
  color: var(--ink);
  font: 19px/1.65 var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Lamp light and its falloff. It stays in place while the page scrolls. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 75% 70% at 82% -8%, var(--lamp), transparent 70%),
    radial-gradient(ellipse 120% 100% at 60% 30%, transparent 45%, rgb(0 0 0 / 0.4) 100%);
}

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

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

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 32px;
  max-width: var(--desk-width);
  margin: 0 auto 56px;
  padding-block: 36px 26px;
  border-bottom: 1px solid var(--desk-rule);
}

.masthead .name {
  color: var(--desk-ink);
  font: 400 28px/1.2 var(--serif);
  letter-spacing: -0.01em;
  text-decoration: none;
}

.masthead nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 24px;
  font: 12px/1.4 var(--sans);
  letter-spacing: 0.02em;
}

.masthead nav a {
  color: var(--desk-ink);
  text-decoration: none;
}

.masthead nav a:hover {
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

.colophon {
  max-width: var(--measure);
  margin: 56px auto 0;
  color: var(--desk-ink-soft);
  font: 12px/1.7 var(--sans);
  letter-spacing: 0.02em;
  text-align: center;
}

.colophon a {
  color: inherit;
}

/* ---------- The sheet ---------- */

.sheet {
  position: relative;
  max-width: var(--sheet-width);
  margin: 0 auto;
  padding: 72px 24px 104px;
  border-radius: 2px;
  background:
    linear-gradient(to bottom left, rgb(255 255 255 / 0.035), transparent 38%, rgb(0 0 0 / 0.07)),
    var(--sheet);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.06),
    inset -1px 0 0 rgb(255 255 255 / 0.03),
    0 0 0 1px rgb(0 0 0 / 0.28),
    -2px 3px 4px rgb(0 0 0 / 0.35),
    -14px 22px 40px -8px rgb(0 0 0 / 0.5),
    -40px 60px 120px -20px rgb(0 0 0 / 0.55);
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background-image: var(--grain-light), var(--grain-dark), var(--mottle);
  background-size: 200px, 260px, 900px;
}

.sheet > * {
  position: relative;
  max-width: var(--measure);
  margin-inline: auto;
}

/* ---------- The text ---------- */

.dateline {
  margin: 0 0 22px;
  color: var(--label);
  font: 11px/1 var(--sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 400;
  text-wrap: balance;
}

h1 {
  margin: 0 0 44px;
  font-size: clamp(2.1rem, 1.2rem + 4.2vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

h2 {
  margin: 2.3em 0 0.7em;
  font-size: 1.5em;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h3 {
  margin: 1.9em 0 0.5em;
  font-size: 1.13em;
  font-style: italic;
  line-height: 1.35;
}

p,
ul,
ol {
  margin: 0 0 1.25em;
}

ul,
ol {
  padding-left: 1.3em;
}

li + li {
  margin-top: 0.4em;
}

li::marker {
  color: var(--ink-soft);
}

.opening::first-letter {
  float: left;
  margin: 0 0.09em 0 0;
  color: var(--initial);
  /* Three lines deep: the cap top meets line one, the foot sits on line three. */
  font-size: 5.77em;
  line-height: 0.85;
}

.sheet a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in srgb, var(--link) 55%, transparent);
  text-underline-offset: 0.18em;
}

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

blockquote {
  margin: 1.8em auto;
  padding-left: 1.2em;
  border-left: 2px solid var(--comment);
  color: var(--quote);
  font-style: italic;
}

blockquote p {
  margin-bottom: 0.4em;
}

blockquote footer {
  color: var(--ink-soft);
  font: 12px/1.5 var(--sans);
  letter-spacing: 0.02em;
}

hr {
  width: 96px;
  height: 1px;
  margin: 3em auto;
  border: 0;
  background: var(--rule);
}

/* ---------- Code ---------- */

code {
  font-family: var(--mono);
  font-size: 0.8em;
}

:not(pre) > code {
  padding: 0.12em 0.28em;
  border-radius: 3px;
  background: rgb(0 0 0 / 0.2);
  color: var(--green);
}

/* A well cut into the paper: dark at the top lip, lit at the bottom lip. */
pre {
  margin: 1.5em auto;
  padding: 16px 18px;
  overflow-x: auto;
  border-radius: 2px;
  background: var(--well);
  box-shadow:
    inset 0 2px 5px rgb(0 0 0 / 0.5),
    inset 0 0 0 1px rgb(0 0 0 / 0.25),
    0 1px 0 rgb(255 255 255 / 0.05);
  font: 13.5px/1.65 var(--mono);
  tab-size: 2;
}

pre code {
  font-size: inherit;
}

.kw { color: var(--pink); }
.fn { color: var(--green); }
.num { color: var(--orange); }
.str { color: var(--yellow); }
.com { color: var(--comment); }
.typ { color: var(--cyan); }
.arg { color: var(--orange); font-style: italic; }

/* ---------- Tables ---------- */

.table-scroll {
  margin-block: 1.6em;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font: 14px/1.5 var(--sans);
}

th,
td {
  padding: 9px 20px 9px 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: baseline;
}

th:last-child,
td:last-child {
  padding-right: 0;
}

th {
  color: var(--label);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* The swatch hangs in the left padding, so a long name wraps under itself. */
td:first-child {
  position: relative;
  padding-left: 1.5em;
  white-space: nowrap;
}

td code {
  color: var(--ink-soft);
  font-size: 12.5px;
}

.swatch {
  position: absolute;
  top: calc(9px + 0.33em);
  left: 0;
  width: 0.85em;
  height: 0.85em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.18);
}

.swatch.background { background: var(--background); }
.swatch.background-dark { background: var(--background-dark); }
.swatch.background-darker { background: var(--background-darker); }
.swatch.selection { background: var(--selection); }
.swatch.foreground { background: var(--foreground); }
.swatch.comment { background: var(--comment); }
.swatch.red { background: var(--red); }
.swatch.orange { background: var(--orange); }
.swatch.yellow { background: var(--yellow); }
.swatch.green { background: var(--green); }
.swatch.cyan { background: var(--cyan); }
.swatch.purple { background: var(--purple); }
.swatch.pink { background: var(--pink); }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  body {
    padding-bottom: 48px;
    font-size: 17px;
  }

  .masthead {
    margin-bottom: 28px;
    padding-block: 24px 18px;
  }

  .masthead .name {
    font-size: 24px;
  }

  .sheet {
    padding: 40px 20px 64px;
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 0.06),
      0 0 0 1px rgb(0 0 0 / 0.28),
      -2px 3px 4px rgb(0 0 0 / 0.35),
      -8px 16px 32px -8px rgb(0 0 0 / 0.55);
  }

  h1 {
    margin-bottom: 32px;
  }

  pre {
    font-size: 12.5px;
  }

  th,
  td {
    padding-right: 12px;
  }

  td:first-child {
    white-space: normal;
  }
}
