/* A notebook page: one margin line, dates to its left, writing to its right. */

:root {
  --paper: #fbfaf7;
  --ink: #1d1c1a;
  --soft: #6d6a63;
  --rule: #e6e3da;
  --line: #bcd6ef;
  --link: #27498a;

  --margin: 6.5rem;
  --gutter: 2.5rem;
  --text: 36rem;
  --offset: calc(var(--margin) + var(--gutter));

  --serif: "Newsreader", "Songti SC", "Noto Serif CJK SC", Georgia, serif;
  --label: "Special Elite", "Courier New", monospace;
  color-scheme: light dark;
}

/* Follows the system until the toggle sets data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161614;
    --ink: #e8e6df;
    --soft: #9a978e;
    --rule: #2c2b27;
    --line: #2f4a66;
    --link: #a3b8e6;
  }
}

:root[data-theme="dark"] {
  --paper: #161614;
  --ink: #e8e6df;
  --soft: #9a978e;
  --rule: #2c2b27;
  --line: #2f4a66;
  --link: #a3b8e6;
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.0625rem/1.55 var(--serif);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

.sheet {
  position: relative;
  max-width: calc(var(--offset) + var(--text) + 3rem);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 1.5rem 0 calc(1.5rem + var(--offset));
}

.sheet::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(1.5rem + var(--margin) + 0.75rem);
  width: 1px;
  background: var(--line);
}

/* Anything in .row or a definition list puts its first child in the margin. */
.row,
dl {
  display: grid;
  grid-template-columns: var(--margin) minmax(0, 1fr);
  column-gap: var(--gutter);
  align-items: baseline;
  margin-left: calc(-1 * var(--offset));
}

.m,
dt {
  font: 400 0.75rem/1.4 var(--label);
  color: var(--soft);
  text-align: right;
  /* Special Elite sits low and small beside the body text; lift it to match. */
  position: relative;
  top: -0.0625rem;
}

/* Masthead */

.masthead {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.25rem 1.5rem;
  padding: 3.5rem 0 4.5rem;
}

.masthead .name {
  font-family: var(--label);
  font-size: 1.1875rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--ink);
}

.masthead nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font: 400 0.8125rem/1.4 var(--label);
}

.masthead nav a,
.theme-toggle {
  color: var(--soft);
  text-decoration: none;
}

.masthead nav a:hover,
.masthead nav a[aria-current],
.theme-toggle:hover {
  color: var(--ink);
}

.theme-toggle {
  display: inline-flex;
  padding: 0.375rem;
  margin: -0.375rem;
  border: 0;
  background: none;
  cursor: pointer;
}

.theme-toggle[hidden] { display: none; }

.theme-toggle svg {
  position: relative;
  top: -0.0625rem;
  width: 0.875rem;
  height: 0.875rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle[data-next="dark"] .sun,
.theme-toggle[data-next="light"] .moon {
  display: none;
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 1px;
}

/* Type */

h1, h2, h3 {
  margin: 0;
  font-weight: 400;
  text-wrap: balance;
}

h1 {
  margin-bottom: 1.5rem;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Section titles stay smaller than the name in the masthead. */
h2,
main > h3 {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.3;
}

main > h2,
main > h3 {
  margin: 2.5rem 0 0.5rem;
  scroll-margin-top: 1.5rem;
}

p { margin: 0 0 1em; }

a {
  color: var(--link);
  text-decoration: none;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover { text-decoration-line: underline; }

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

/* Home */

.margin-note {
  position: absolute;
  margin-top: 0.1875rem;
  left: 1.5rem;
  width: var(--margin);
  text-align: right;
}

.margin-note a {
  display: block;
  font: 400 0.75rem/1.7 var(--label);
  color: var(--soft);
  text-decoration: none;
}

.margin-note a:hover { color: var(--ink); }

.contents .row {
  padding: 0.5rem 0;
  color: inherit;
  text-decoration: none;
}

.contents .title { color: var(--link); }
.contents a:hover .title { text-decoration-line: underline; }
.contents .summary { display: block; font-size: 1rem; line-height: 1.4; color: var(--soft); }

dl { row-gap: 0.625rem; margin-top: 0; margin-bottom: 0; }
dd { margin: 0; font-size: 1rem; line-height: 1.45; }
dd p { margin: 0; }

details { margin-top: 0.625rem; }

summary {
  width: fit-content;
  padding: 0.25rem 0 0.75rem;
  font: 400 0.8125rem/1.4 var(--serif);
  color: var(--soft);
  cursor: pointer;
}

summary:hover { color: var(--ink); }

details[open] > summary { display: none; }

/* Research */

main > ul { font-size: 0.9375rem; }

.pointer { margin-bottom: 1.0625rem; font-size: 0.9375rem; color: var(--soft); }

.cite {
  color: var(--link);
  font-size: 0.85em;
  text-decoration: none;
  white-space: nowrap;
}

.cite:hover { text-decoration: underline; }

.paper {
  margin-bottom: 1.5rem;
  scroll-margin-top: 1.5rem;
}

.paper:target .m { color: var(--link); }

.paper h3 {
  font-size: 0.9375rem;
  line-height: 1.35;
  font-weight: 500;
  text-wrap: pretty;
}

.paper p { margin: 0; }

.authors {
  margin-top: 0.125rem !important;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--soft);
}

.authors b { font-weight: 500; color: var(--ink); }

.meta {
  margin-top: 0.25rem !important;
  font: 400 0.8125rem/1.6 var(--serif);
  color: var(--soft);
}

.gloss { margin-top: 0.375rem; font-size: 1rem; line-height: 1.45; }

.footnote {
  margin-top: 3rem;
  font: 400 0.8125rem/1.4 var(--serif);
  color: var(--soft);
}

/* Notes */

.note .row { margin-bottom: 1.5rem; }
.note h1 { margin: 0; }
.note h2 { margin: 2.5em 0 0.75rem; }
.note h3 { margin: 2em 0 0.5rem; font-weight: 500; font-size: inherit; }
.note ul, .note ol { padding-left: 1.25em; }
.note li { margin-bottom: 0.25em; }
.note img { max-width: 100%; height: auto; }

blockquote {
  margin: 1.5em 0;
  padding-left: 1em;
  border-left: 1px solid var(--rule);
  color: var(--soft);
  font-style: italic;
}

code {
  font: 400 0.8125em/1 ui-monospace, Menlo, monospace;
}

pre {
  margin: 1.5em 0;
  padding: 1rem 0;
  overflow-x: auto;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

pre code { line-height: 1.6; }

.highlight { background: none; }
.highlight .c, .highlight .c1, .highlight .cm, .highlight .cs { color: var(--soft); font-style: italic; }
.highlight .k, .highlight .kc, .highlight .kd, .highlight .kn, .highlight .kp, .highlight .kr, .highlight .kt { font-weight: 600; }
.highlight .s, .highlight .s1, .highlight .s2, .highlight .sb, .highlight .sd, .highlight .se { color: var(--link); }

table {
  width: 100%;
  margin: 1.5em 0;
  border-collapse: collapse;
  font-size: 1rem;
}

th, td {
  padding: 0.375rem 0.75rem 0.375rem 0;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}

th { font-weight: 500; }

hr { margin: 3em 0; border: 0; border-top: 1px solid var(--rule); }

.footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9375rem;
}

.back {
  margin-top: 3rem;
  font: 400 0.8125rem/1.4 var(--serif);
}

/* Footer */

footer {
  margin-top: 6rem;
  padding-bottom: 3.5rem;
  font: 400 0.8125rem/1.6 var(--serif);
  color: var(--soft);
}

footer p { margin: 0; }

/* Narrow screens: the margin folds in, dates sit above what they label. */

@media (max-width: 44rem) {
  .sheet { padding: 0 1rem; }
  .sheet::before { display: none; }

  .row, dl {
    display: block;
    margin-left: 0;
  }

  .m, dt { display: block; text-align: left; }
  .m:empty { display: none; }

  dt { margin-top: 1rem; }

  .masthead { padding: 1.5rem 0 2.5rem; }

  .margin-note {
    position: static;
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    width: auto;
    margin-bottom: 1.25rem;
    text-align: left;
  }

  .margin-note a { display: inline; margin-right: 0.75rem; }

  .contents .m { margin-bottom: 0.125rem; }

  .row.paper {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr);
    column-gap: 0.25rem;
  }
}
