:root {
  --paper: rgb(248, 248, 235);
  --ink: rgb(22, 22, 16);
  --green: #153324;
  --rule: rgba(22, 22, 16, 0.35);
  --accent: var(--green);
  --font: "Libre Caslon Text", Georgia, serif;
  --font-title: "Old Standard TT", Georgia, serif;
  --sidebar: 255px;
  --gutter: 18px;
}

/* Dark mode: switched on by the lamp. */
html[data-theme="dark"] {
  --paper: #153324;
  --ink: rgb(248, 248, 235);
  --rule: rgba(248, 248, 235, 0.35);
  --accent: #a9c9b1;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.53;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
}

.defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* Paper texture: a scanned book page multiplied faintly over the light page. */
html:not([data-theme="dark"]) body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("../img/paper-scan.jpg") center / cover no-repeat;
  mix-blend-mode: multiply;
  opacity: 0.06;
  pointer-events: none;
}

a {
  color: inherit;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- layout ---------- */

.page {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 740px);
  column-gap: calc(341px - var(--sidebar) - var(--gutter));
  padding: 56px var(--gutter) 120px;
}

.masthead {
  margin-bottom: 42px;
}

.rail {
  align-self: start;
}

/* Keep the lamp, name, tabs and sidebar in view while reading, as long as
   the screen is tall enough to show them all. */
@media (min-height: 640px) {
  .rail {
    position: sticky;
    top: 56px;
  }
}

.content {
  min-width: 0;
}

/* ---------- masthead ---------- */

.lamp {
  position: relative;
  display: block;
  width: 107px;
  height: 146px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.lamp-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

/* The lamp art is drawn in --green; lighten it so it shows on the dark page. */
html[data-theme="dark"] .lamp-img {
  filter: brightness(0) invert(97%) sepia(6%);
}

/* Glow: light pooling under the shade. Light mode is the lamp switched on,
   so it glows softly; dark mode is the lamp off, so it only hints on hover. */
.lamp::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(42% 24% at 56% 40%, rgba(255, 200, 90, 0.7), rgba(255, 200, 90, 0));
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

/* On the dark page, add light rather than tint. */
html[data-theme="dark"] .lamp::before {
  background: radial-gradient(42% 24% at 56% 40%, rgba(255, 212, 128, 0.9), rgba(255, 212, 128, 0));
  mix-blend-mode: screen;
}

.lamp:hover::before,
.lamp:focus-visible::before {
  opacity: 1;
}

html[data-theme="dark"] .lamp::before {
  opacity: 0;
}

html[data-theme="dark"] .lamp:hover::before,
html[data-theme="dark"] .lamp:focus-visible::before {
  opacity: 0.45;
}

.site-name {
  margin: 18px 0 18px;
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  filter: url(#ink);
}

.tabs {
  display: flex;
  gap: 7px;
}

.tab {
  padding: 11px 12px;
  border: 1px solid var(--rule);
  font-size: 16px;
  line-height: 1.4;
  text-decoration: none;
}

.tab:hover {
  border-color: var(--ink);
}

.tab.is-active {
  border-color: var(--ink);
}

/* ---------- sidebar ---------- */

.sidebar p {
  margin: 0 0 19px;
}

.archive-note {
  margin-top: 30px !important;
}

.archive-note a {
  display: inline-block;
  margin-top: 4px;
}

/* ---------- essay ---------- */

.piece-title {
  margin: 0 0 56px;
  max-width: 987px;
  font-size: 44px;
  font-family: var(--font-title);
  font-weight: 700;
  filter: url(#ink);
  line-height: 1.14;
}

.piece-prompt {
  margin: -28px 0 56px;
  padding-left: 18px;
  border-left: 1px solid var(--rule);
  font-style: italic;
}

/* Keep reading lines to roughly 70 characters. */
.prose,
.references {
  max-width: 36em;
}

.prose p {
  margin: 0 0 25px;
}

.prose em,
.references em {
  font-style: italic;
}

.prose a,
.references a {
  overflow-wrap: anywhere;
}

.references {
  margin-top: 72px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
  font-size: 15px;
}

.references h2 {
  margin: 0 0 25px;
  font-size: 18px;
  font-weight: 400;
}

.references p {
  margin: 0 0 14px;
  padding-left: 2em;
  text-indent: -2em;
}

/* ---------- index ---------- */

.index-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.index-list a {
  display: block;
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
  text-decoration: none;
}

.index-title {
  display: block;
  font-size: 22px;
  line-height: 1.3;
}

.index-list a:hover .index-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.index-meta {
  display: block;
  margin-top: 8px;
  font-size: 15px;
}

.empty {
  margin: 0;
}

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 32px;
  }

  .masthead {
    margin-bottom: 32px;
  }

  .rail {
    position: static;
  }

  .sidebar {
    margin-bottom: 40px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--rule);
  }

  .piece-title {
    font-size: 30px;
    margin-bottom: 44px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .lamp:active {
    transform: translateY(1px);
  }
}
