@font-face {
  font-family: "Instrument Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/instrument-serif-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Instrument Serif";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/instrument-serif-latin-400-italic.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}

:root {
  --paper: #f2ede3;
  --paper-deep: #e9e2d4;
  --ink: #1b1a17;
  --muted: #6b665c;
  --rule: rgb(27 26 23 / 7%);
  --hair: rgb(27 26 23 / 22%);
  --accent: #c2301b;
  --accent-soft: rgb(194 48 27 / 55%);
  --grain-opacity: 0.35;
  --serif:
    "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --line: 2rem;
  --margin-col: 14rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15140f;
    --paper-deep: #1c1a14;
    --ink: #ece6d8;
    --muted: #a39d8f;
    --rule: rgb(236 230 216 / 6%);
    --hair: rgb(236 230 216 / 20%);
    --accent: #e85a40;
    --accent-soft: rgb(232 90 64 / 60%);
    --grain-opacity: 0.18;
  }
}

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

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background-color: var(--paper);
  background-image: radial-gradient(
    120% 90% at 85% 0%,
    var(--paper) 0%,
    var(--paper) 45%,
    var(--paper-deep) 100%
  );
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Paper grain, drawn once over everything; never intercepts input. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.09 0 0 0 0 0.07 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  body::after {
    mix-blend-mode: screen;
  }
}

::selection {
  background: var(--accent);
  color: var(--paper);
}

/* ------------------------------------------------------------------ sheet */
.sheet {
  position: relative;
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  grid-template-areas:
    "mast  mast"
    "marg  entry"
    "foot  foot";
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 78rem;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3.5rem);
}

/* Ledger ruling + the red margin line that every register sheet has. */
.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px),
    var(--rule) var(--line)
  );
  mask-image: linear-gradient(
    to bottom,
    transparent,
    #000 12%,
    #000 88%,
    transparent
  );
}

.sheet::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(clamp(1rem, 4vw, 3.5rem) + var(--margin-col) - 1.5rem);
  width: 0;
  border-left: 1.5px solid var(--accent-soft);
  box-shadow: 4px 0 0 -2.5px var(--accent-soft);
  transform-origin: top;
  animation: draw 1.1s cubic-bezier(0.6, 0, 0.2, 1) 0.1s both;
  pointer-events: none;
}

/* --------------------------------------------------------------- masthead */
.masthead {
  position: relative;
  grid-area: mast;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: clamp(1.5rem, 4vw, 2.75rem) 0 clamp(2.5rem, 7vw, 5rem);
  border-bottom: 1px solid var(--hair);
  margin-bottom: clamp(2rem, 6vw, 4.5rem);
}

.wordmark {
  margin: 0;
  font-size: clamp(1.35rem, 2.4vw, 1.7rem);
  letter-spacing: 0.005em;
  animation: rise 0.8s ease-out both;
}

.serial,
.margin,
.ledger,
.foot {
  font-family: var(--mono);
}

.serial {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  animation: rise 0.8s ease-out 0.1s both;
}

/* ----------------------------------------------------------------- margin */
.margin {
  grid-area: marg;
  padding-right: 3rem;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  animation: rise 0.8s ease-out 0.55s both;
}

.margin dl {
  margin: 0.6rem 0 0;
  display: grid;
  gap: 1.25rem;
}

.margin dt {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-size: 0.66rem;
}

.margin dd {
  margin: 0.2rem 0 0;
  color: var(--ink);
}

/* ------------------------------------------------------------------ entry */
.entry {
  grid-area: entry;
  max-width: 50rem;
  padding-bottom: clamp(3rem, 8vw, 6rem);
}

h1 {
  margin: 0;
  font-weight: 400;
  font-size: clamp(3.1rem, 9.2vw, 7.6rem);
  line-height: 0.94;
  letter-spacing: -0.022em;
}

h1 .line {
  display: block;
  animation: rise 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

h1 .line:nth-child(1) {
  animation-delay: 0.2s;
}

h1 .line:nth-child(2) {
  animation-delay: 0.34s;
}

h1 em {
  font-style: italic;
}

.lede {
  max-width: 34rem;
  margin: clamp(1.75rem, 4vw, 2.75rem) 0 0;
  font-size: clamp(1.2rem, 1.9vw, 1.45rem);
  line-height: 1.42;
  animation: rise 0.9s ease-out 0.5s both;
}

.de {
  margin: 0.9rem 0 0;
  font-style: italic;
  font-size: clamp(1.05rem, 1.5vw, 1.2rem);
  color: var(--muted);
  animation: rise 0.9s ease-out 0.62s both;
}

/* ----------------------------------------------------------------- covers */
.covers {
  max-width: 36rem;
  margin-top: clamp(2.5rem, 5vw, 3.5rem);
  animation: rise 0.9s ease-out 0.7s both;
}

.covers h2 {
  margin: 0 0 0.6rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.covers p {
  margin: 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--hair);
  font-size: clamp(1.02rem, 1.3vw, 1.12rem);
  line-height: 1.55;
}

/* ----------------------------------------------------------------- ledger */
.ledger {
  margin-top: clamp(2.75rem, 6vw, 4.25rem);
  max-width: 30rem;
  animation: rise 0.9s ease-out 0.85s both;
}

.ledger h2 {
  margin: 0 0 0.6rem;
  font-size: 0.66rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

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

.ledger li {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--hair);
  font-size: 0.82rem;
}

/* Dot leaders between label and figure, as in a printed register. */
.ledger li span {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  white-space: nowrap;
}

.ledger li span::after {
  content: "";
  flex: 1;
  min-width: 1rem;
  border-bottom: 1px dotted var(--hair);
  transform: translateY(-0.2em);
}

.ledger b {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.ledger .accent b {
  color: var(--accent);
}

/* ------------------------------------------------------------------ stamp */
.stamp {
  /* Centred on the masthead rule, right-aligned: clear of the headline at every width. */
  position: absolute;
  right: 0;
  bottom: calc(clamp(6.5rem, 12vw, 10.5rem) / -2);
  width: clamp(6.5rem, 12vw, 10.5rem);
  aspect-ratio: 1;
  color: var(--accent);
  opacity: 0.9;
  mix-blend-mode: multiply;
  transform: rotate(-14deg);
  animation: stamp 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) 1.15s both;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .stamp {
    mix-blend-mode: normal;
  }
}

.stamp svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.stamp-outer,
.stamp-inner {
  fill: none;
  stroke: currentColor;
}

.stamp-outer {
  stroke-width: 3;
}

.stamp-inner {
  stroke-width: 1.25;
}

.stamp-ring {
  fill: currentColor;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 14.5px;
  text-transform: uppercase;
}

.stamp-core {
  fill: currentColor;
  font-family: var(--serif);
  font-style: italic;
  font-size: 30px;
  text-anchor: middle;
}

/* ------------------------------------------------------------------- foot */
.foot {
  grid-area: foot;
  display: grid;
  grid-template-columns: var(--margin-col) minmax(0, 1fr);
  gap: 0;
  padding: 1.5rem 0 clamp(1.5rem, 4vw, 2.5rem);
  border-top: 1px solid var(--hair);
  font-size: 0.74rem;
  line-height: 1.65;
  color: var(--muted);
  animation: rise 0.9s ease-out 0.9s both;
}

.colophon {
  grid-column: 1;
  grid-row: 1;
  margin: 0;
}

.links {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.links a {
  color: inherit;
  text-underline-offset: 0.25em;
}

.links a:hover,
.links a:focus-visible {
  color: var(--accent);
}

/* --------------------------------------------------------- document page */
.doc h1 {
  font-size: clamp(2.6rem, 6vw, 4.75rem);
  margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.doc h2 {
  margin: 2rem 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.doc p {
  max-width: 40rem;
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.6;
}

.doc a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

/* ------------------------------------------------------------- 404 page */
.lost h1 {
  font-size: clamp(2.6rem, 7vw, 5.5rem);
}

.home {
  color: inherit;
  text-decoration: none;
}

.lost a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

/* ----------------------------------------------------------------- motion */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(0.6rem);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes draw {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

@keyframes stamp {
  0% {
    opacity: 0;
    transform: rotate(-26deg) scale(1.9);
  }
  70% {
    opacity: 0.95;
  }
  100% {
    opacity: 0.9;
    transform: rotate(-14deg) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ------------------------------------------------------------- narrow */
@media (max-width: 760px) {
  :root {
    --margin-col: 0;
  }

  .sheet {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "mast"
      "entry"
      "marg"
      "foot";
    grid-template-rows: auto auto 1fr auto;
  }

  .sheet::after {
    left: calc(clamp(1rem, 4vw, 3.5rem) - 0.55rem);
  }

  .masthead {
    padding-bottom: 8rem;
  }

  .entry {
    padding-bottom: 2.5rem;
  }

  .margin {
    padding: 0 0 2.5rem;
  }

  .margin dl {
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  }

  .stamp {
    bottom: 0.75rem;
    width: 6.75rem;
  }

  .foot {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }

  .colophon,
  .links {
    grid-column: 1;
    grid-row: auto;
    justify-self: start;
  }
}
