/* ——— type ——— */

@font-face {
  font-family: newsreader;
  src: url(fonts/newsreader.woff2) format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: newsreader;
  src: url(fonts/newsreader-italic.woff2) format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

/* a system serif reshaped to newsreader's proportions, so the page does not move when the real thing arrives */
@font-face {
  font-family: "newsreader fallback";
  src: local("Times New Roman"), local("Liberation Serif"), local("Tinos");
  size-adjust: 104.6%;
  ascent-override: 70.3%;
  descent-override: 25.3%;
  line-gap-override: 0%;
}

/* ——— tokens ——— */

:root {
  color-scheme: only light;

  --paper: #fcfbf8;
  --wash: #f4f1ea;
  --rule: #e6e2d8;
  --ink: #1c1b18;
  --ink-2: #4b4841;
  --ink-3: #6f6b61;
  --accent: #9a4a26;

  /* chart inks, in the order series take them. every pair holds apart for colour-blind readers on this paper.
     assets/chart.css draws with them, and a hand-drawn svg can too */
  --c1: #3550c0;
  --c2: #c24a32;
  --c3: #239a80;
  --c4: #ad8a00;
  --quiet: #cdc7ba;

  --serif: newsreader, "newsreader fallback", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 30rem;
  --gutter: clamp(1.25rem, 4.4vw, 3rem);
  --top: clamp(2.5rem, 9vh, 5.5rem);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* one ink per section */
[data-section="software"] { --accent: #2b3ea8; }
[data-section="biology"] { --accent: #1e6b4d; }
[data-section="astronomy"] { --accent: #5a3d9a; }
[data-section="geography"] { --accent: #7a5510; }
[data-section="history"] { --accent: #9a3324; }
[data-section="linguistics"] { --accent: #86306e; }
[data-section="gaming"] { --accent: #a3264f; }
[data-section="economics"] { --accent: #0f6470; }
[data-section="mathematics"] { --accent: #4a5568; }
[data-section="physics"] { --accent: #1f5f8f; }
[data-section="typography"] { --accent: #54610f; }
[data-section="notes"] { --accent: #6b5d4d; }

/* ——— base ——— */

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

html {
  font-size: clamp(1.125rem, 1.02rem + 0.42vw, 1.3125rem);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
  scroll-padding-top: 2.5rem;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.55 var(--serif);
  font-kerning: normal;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
}

::selection {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

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

main:focus,
h1:focus {
  outline: 0;
}

a {
  color: inherit;
  text-decoration-thickness: 0.055em;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, currentColor 32%, transparent);
  transition: color 0.2s, text-decoration-color 0.2s;
}

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

h1,
h2,
h3,
p,
figure {
  margin: 0;
}

.skip {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 10;
  padding: 0.4rem 0.8rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.85rem;
  text-decoration: none;
  border-radius: 0.4rem;
  transform: translateY(-300%);
}

.skip:focus {
  transform: none;
}

/* ——— frame ——— */

.page {
  display: grid;
  grid-template-columns: 11.5rem minmax(0, 1fr);
  column-gap: clamp(2.5rem, 6vw, 6rem);
  max-width: 76rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main {
  min-width: 0;
  min-height: 100dvh;
  padding-block: var(--top) 7rem;
  transition: opacity 0.3s;
}

main[aria-busy="true"] {
  opacity: 0.45;
}

/* ——— sidebar ——— */

.side {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  /* room on the left for the dot that marks the current section */
  margin-left: -1.25rem;
  padding: var(--top) 0 2rem 1.25rem;
  overflow-y: auto;
  scrollbar-width: none;
  font-size: 0.92rem;
}

.name {
  font-size: 1.06rem;
  font-weight: 560;
  letter-spacing: -0.012em;
  text-decoration: none;
}

.menu {
  display: none;
}

#nav {
  margin-top: 2.4rem;
}

.sections,
.outline ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sections a {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  padding-block: 0.2em;
  color: var(--ink-3);
  text-decoration: none;
}

.sections a::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -0.95em;
  width: 0.36em;
  height: 0.36em;
  margin-top: -0.18em;
  border-radius: 50%;
  background: var(--accent);
  transform: scale(0);
  transition: transform 0.35s var(--ease);
}

.sections a:hover,
.sections a[aria-current] {
  color: var(--ink);
}

.sections a[aria-current]::before {
  transform: none;
}

#find {
  margin-top: 0.5em;
  padding: 0.2em 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  cursor: pointer;
}

#find:hover {
  color: var(--ink);
}

.count {
  font-size: 0.74em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}

.outline {
  margin-top: 2.6rem;
}

.label {
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  letter-spacing: 0.035em;
  color: var(--ink-3);
}

.outline a {
  display: block;
  padding: 0.24em 0 0.24em 0.9em;
  border-left: 1px solid var(--rule);
  color: var(--ink-3);
  font-size: 0.86rem;
  line-height: 1.3;
  text-decoration: none;
  transition: color 0.2s, border-color 0.2s;
}

.outline a:hover,
.outline a[aria-current] {
  color: var(--ink);
}

.outline a[aria-current] {
  border-left-color: var(--accent);
}

/* ——— headings of a page ——— */

.head {
  margin-bottom: 3rem;
}

.kicker,
.meta {
  font-size: 0.82rem;
  letter-spacing: 0.015em;
  color: var(--ink-3);
}

.kicker a,
.meta a {
  color: var(--accent);
  text-decoration: none;
}

.kicker a:hover,
.meta a:hover {
  text-decoration: underline;
}

.dot::before {
  content: "·";
  margin-inline: 0.5em;
}

h1 {
  max-width: 20ch;
  margin-top: 0.55rem;
  font-size: clamp(2.05rem, 1.2rem + 4.2vw, 3rem);
  font-weight: 420;
  line-height: 1.04;
  letter-spacing: -0.026em;
  text-wrap: balance;
}

.deck {
  max-width: 28rem;
  margin-top: 1.1rem;
  font-size: 1.26rem;
  font-weight: 380;
  line-height: 1.36;
  color: var(--ink-2);
  text-wrap: pretty;
}

.statement {
  max-width: 21ch;
  margin-top: 0;
  font-size: clamp(1.7rem, 1.1rem + 3vw, 2.35rem);
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: -0.02em;
}

.home .label {
  margin: 4rem 0 0.9rem;
}

.empty {
  color: var(--ink-3);
}

/* ——— lists of articles ——— */

.index {
  max-width: 34rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry {
  position: relative;
  padding-block: 1.5rem 1.6rem;
  border-top: 1px solid var(--rule);
}

.entry:last-child {
  border-bottom: 1px solid var(--rule);
}

.entry h2 {
  margin-top: 0.3rem;
  font-size: 1.5rem;
  font-weight: 460;
  line-height: 1.14;
  letter-spacing: -0.016em;
  text-wrap: balance;
}

.entry h2 a {
  text-decoration: none;
}

/* the whole entry is the link */
.entry h2 a::after {
  content: "";
  position: absolute;
  inset: 0;
}

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

.home > .meta {
  margin-top: 1.6rem;
}

.entry .meta a {
  position: relative;
  z-index: 1;
}

.entry .deck {
  margin-top: 0.4rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.45;
}

/* ——— prose ——— */

.prose > * {
  max-width: var(--measure);
  margin-block: 0;
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose > :is(figure, table, pre, .scroll) {
  max-width: none;
}

.prose :is(blockquote, li, dd, aside, details) > * + * {
  margin-top: 0.6em;
}

.prose p {
  text-wrap: pretty;
  hanging-punctuation: first;
}

.prose > p:first-child {
  font-size: 1.14rem;
  line-height: 1.5;
}

.prose a {
  color: var(--accent);
}

.prose h2 {
  position: relative;
  margin-top: 3.4rem;
  font-size: 1.62rem;
  font-weight: 470;
  line-height: 1.14;
  letter-spacing: -0.017em;
  text-wrap: balance;
}

.prose h2 + * {
  margin-top: 0.9rem;
}

.prose h3 {
  margin-top: 2.1rem;
  font-size: 1.14rem;
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.006em;
  text-wrap: balance;
}

.prose h3 + * {
  margin-top: 0.3rem;
}

/* a quiet handle on each section, for linking to it */
.anchor {
  position: absolute;
  right: 100%;
  padding-right: 0.4em;
  color: var(--ink-3);
  font-weight: 300;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

.prose h2:hover .anchor,
.anchor:focus-visible {
  opacity: 1;
}

.anchor:hover {
  color: var(--accent);
}

.prose strong,
.prose b {
  font-weight: 620;
}

.prose small,
.prose .meta,
.prose figcaption {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--ink-3);
}

.prose :is(ul, ol) {
  padding-left: 1.25em;
}

.prose li + li {
  margin-top: 0.5em;
}

.prose li::marker {
  color: var(--accent);
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
}

.prose blockquote {
  margin-inline: 0;
  padding-left: 1.1em;
  border-left: 2px solid var(--accent);
  color: var(--ink-2);
}

.prose cite {
  font-style: normal;
}

/* an abbreviation keeps its capitals, set a touch smaller so they do not shout on a lowercase page */
.prose abbr {
  font-size: 0.86em;
  letter-spacing: 0.045em;
}

.prose hr {
  width: 3rem;
  height: 1px;
  margin: 3rem 0;
  border: 0;
  background: var(--ink);
}

.prose :is(img, figure > svg) {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.2rem;
}

.prose sup {
  position: relative;
  top: -0.5em;
  font-size: 0.68em;
  line-height: 0;
  vertical-align: baseline;
  font-variant-numeric: tabular-nums;
}

.prose sup a {
  padding-inline: 0.1em;
  text-decoration: none;
}

.prose :is(code, kbd, samp, pre) {
  font-family: var(--mono);
  font-size: 0.8em;
}

.prose :not(pre) > :is(code, kbd) {
  padding: 0.12em 0.36em;
  border-radius: 0.3em;
  background: var(--wash);
}

.prose kbd {
  box-shadow: inset 0 -1px 0 var(--rule), 0 0 0 1px var(--rule);
}

.prose mark {
  border-radius: 0.15em;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: inherit;
}

/* terms and their definitions */
.prose dl {
  margin-bottom: 0;
}

.prose dt {
  margin-top: 1.5rem;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.3;
}

.prose dt small {
  margin-left: 0.5em;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.prose dd {
  margin: 0.25rem 0 0;
}

/* tables: wider than the text, scrolled sideways when they have to be */
.prose figure {
  margin-top: 2rem;
}

.prose figcaption {
  max-width: var(--measure);
  margin-top: 0.8rem;
}

.scroll {
  overflow-x: auto;
  border-top: 1.5px solid var(--ink);
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.prose caption {
  padding-block: 0.7em 0.2em;
  text-align: left;
  font-weight: 600;
}

.prose :is(th, td) {
  padding: 0.64em 0.55em;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  white-space: nowrap;
  background-clip: padding-box;
}

.prose thead th {
  vertical-align: bottom;
  font-size: 0.92em;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.25;
  color: var(--ink-3);
  white-space: normal;
}

.prose :is(th, td):first-child {
  padding-left: 0;
}

.prose :is(th, td):last-child {
  padding-right: 0;
}

.prose :is(th, td):is(.l, .words) {
  text-align: left;
}

/* a cell of words rather than a number: it wraps where it runs long, with room to do it in */
.prose .words {
  min-width: 10em;
  white-space: normal;
}

.prose tbody tr:has(.words) > * {
  vertical-align: baseline;
}

/* the first column names the row, and stays put while the numbers scroll */
.prose th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background-color: var(--paper);
  text-align: left;
}

.prose tbody th {
  font-weight: 540;
}

/* a position in a ranking, hung in front of the name */
.prose th:has(.rank) {
  padding-left: 2.2em;
}

.rank {
  position: absolute;
  left: 0;
  font-weight: 400;
  color: var(--ink-3);
}

.prose td.best {
  color: var(--accent);
  font-weight: 640;
  background-color: color-mix(in srgb, var(--accent) 9%, transparent);
}

.prose td.none {
  color: color-mix(in srgb, var(--ink-3) 55%, transparent);
}

.swatch {
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  margin-right: 0.4em;
  border-radius: 0.15em;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
}

@media (hover: hover) {
  .prose tbody tr:hover > * {
    background-color: var(--wash);
  }

  .prose tbody tr:hover > td.best {
    background-color: color-mix(in srgb, var(--accent) 14%, var(--wash));
  }
}

/* a soft edge appears beside the first column once the table has moved under it */
.prose th:first-child::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: -1px;
  left: 100%;
  width: 0.9rem;
  background: linear-gradient(to right, rgb(28 27 24 / 0.1), transparent);
  opacity: 0;
  pointer-events: none;
}

@supports (animation-timeline: scroll()) {
  .scroll {
    scroll-timeline: --sideways inline;
  }

  .prose th:first-child::after {
    animation: stuck linear both;
    animation-timeline: --sideways;
    animation-range: 0 2rem;
  }

  @keyframes stuck {
    to {
      opacity: 1;
    }
  }
}

.flash {
  animation: flash 1.8s ease-out;
}

@keyframes flash {
  from {
    background-color: color-mix(in srgb, var(--accent) 14%, transparent);
    box-shadow: 0 0 0 0.4rem color-mix(in srgb, var(--accent) 14%, transparent);
  }
}

/* ——— foot of an article ——— */

.tail {
  display: grid;
  gap: 1.1rem;
  max-width: var(--measure);
  margin-top: 5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.tail a {
  justify-self: start;
  text-decoration: none;
}

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

.tail small {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.035em;
  color: var(--ink-3);
}

/* the parts of a series, in order, with the one being read left plain */
.tail ol {
  margin: 0.15rem 0 0;
  padding-left: 1.2em;
}

.tail li::marker {
  font-size: 0.86em;
}

.tail :is([aria-current], ::marker) {
  color: var(--ink-3);
}

/* ——— motion ——— */

.enter {
  animation: appear 0.3s ease both;
}

@keyframes appear {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(0.4rem);
  }
}

/* movement is for readers who have not asked for less of it. fades stay either way. */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  .enter {
    animation: rise 0.45s var(--ease) both;
  }
}

@media (prefers-reduced-motion: reduce) {
  #nav,
  .sections a::before {
    transition: none;
  }
}

/* how far down the article you are, drawn by the scroll itself */
.progress {
  display: none;
}

@supports (animation-timeline: scroll()) {
  :root[data-view="article"] .progress {
    display: block;
    position: fixed;
    inset: 0 0 auto;
    z-index: 6;
    height: 2px;
    background: var(--accent);
    transform-origin: 0 50%;
    animation: progress linear both;
    animation-timeline: scroll(root block);
  }

  @keyframes progress {
    from {
      transform: scaleX(0);
    }
  }
}

/* ——— narrow screens: the sidebar folds into a bar ——— */

@media (max-width: 60em) {
  html {
    scroll-padding-top: 4.6rem;
  }

  .page {
    display: block;
    padding-inline: 0;
  }

  .side {
    z-index: 5;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: color-mix(in srgb, var(--paper) 86%, transparent);
    -webkit-backdrop-filter: blur(12px) saturate(1.5);
    backdrop-filter: blur(12px) saturate(1.5);
    border-bottom: 1px solid var(--rule);
  }

  .mast {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.72rem var(--gutter);
  }

  .menu {
    display: block;
    margin: -0.5rem -0.6rem;
    padding: 0.5rem 0.6rem;
    border: 0;
    background: none;
    color: var(--ink-3);
    font: inherit;
    cursor: pointer;
  }

  .menu[aria-expanded="true"] {
    color: var(--ink);
  }

  #nav {
    position: absolute;
    inset: 100% 0 auto;
    display: grid;
    grid-template-rows: 0fr;
    margin: 0;
    visibility: hidden;
    background: var(--paper);
    transition: grid-template-rows 0.4s var(--ease), visibility 0.4s, box-shadow 0.4s;
  }

  .side[data-open] #nav {
    grid-template-rows: 1fr;
    visibility: visible;
    box-shadow: 0 1px 0 var(--rule), 0 1.5rem 2rem -1.5rem rgb(28 27 24 / 0.18);
  }

  .nav-inner {
    min-height: 0;
    max-height: calc(100dvh - 3.5rem);
    padding-inline: var(--gutter);
    overflow: hidden auto;
  }

  .sections a::before {
    position: static;
    order: 1;
    align-self: center;
    margin: 0;
  }

  .sections,
  #find {
    padding-block: 0.6rem 1.2rem;
    font-size: 1.1rem;
  }

  .sections a {
    padding-block: 0.34em;
  }

  .outline {
    margin-top: 0.4rem;
    padding-bottom: 1.6rem;
  }

  .outline a {
    padding-block: 0.4em;
    font-size: 0.95rem;
  }

  main {
    padding: 2.4rem var(--gutter) 5rem;
  }

  .head {
    margin-bottom: 2.4rem;
  }

  /* tables run to the edges of the screen */
  .scroll {
    margin-inline: calc(-1 * var(--gutter));
  }

  .prose :is(th, td):first-child,
  .prose caption {
    padding-left: var(--gutter);
  }

  .prose :is(th, td):last-child {
    padding-right: var(--gutter);
  }

  .prose tbody th {
    min-width: 9.5rem;
    white-space: normal;
  }

  .prose th:has(.rank) {
    min-width: 11rem;
    padding-left: calc(var(--gutter) + 2em);
  }

  /* beside a column of words the name keeps to one line and its own width: the words are what gives */
  .prose tbody tr:has(.words) > th {
    min-width: 0;
    white-space: nowrap;
  }

  .rank {
    left: var(--gutter);
  }

  .anchor {
    display: none;
  }
}

/* ——— paper ——— */

@media print {
  .side,
  .progress,
  .skip,
  .tail,
  .anchor {
    display: none !important;
  }

  .page {
    display: block;
    max-width: none;
    padding: 0;
  }

  main {
    padding: 0;
  }

  .scroll {
    overflow: visible;
  }
}
