:root {
  --paper: #ffffff;
  --ink: #222222;
  --quiet: #757575;
  --line: #b9b9b9;
  --wash: #f2f2f0;
  --green: #1b6e4a;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Hanken Grotesk", "Helvetica Neue", Arial, "Hiragino Sans", "Yu Gothic", sans-serif;
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151515;
    --ink: #e9e9e7;
    --quiet: #9a9a98;
    --line: #5c5c5c;
    --wash: #212121;
    --green: #86cba6;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.5;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 39rem;
  margin: 0 auto;
  padding: clamp(2.5rem, 8vh, 5rem) 1.5rem 4rem;
}

.top { padding-bottom: 0.4rem; }
/* Site links. One group per line on narrow screens. */
.side {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-bottom: 2rem;
}
.side .group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.1rem;
}
.side a, .crumbs a {
  color: var(--quiet);
  text-decoration: none;
}
.side a[aria-current] { color: var(--ink); }
.side a:hover, .crumbs a:hover { color: var(--green); }
/* The path back up, above the title of an inner page */
.crumbs { margin-bottom: 0.6rem; color: var(--quiet); }

h1, h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
}
h1 {
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.kana {
  margin-left: 0.75rem;
  color: var(--quiet);
  font-family: var(--mincho);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
section + section { margin-top: 2.5rem; }
.content > :not(section) + section { margin-top: 2.5rem; }
/* Section names are quiet labels, set like the text around them */
h2 {
  margin-bottom: 0.45rem;
  font-family: var(--sans);
  font-size: 1em;
  font-weight: 400;
  line-height: 1.5;
  color: var(--quiet);
}
h2 small {
  margin-left: 0.5rem;
  font-size: 1em;
  font-weight: 400;
}

p { margin: 0; text-wrap: pretty; }
p + p { margin-top: 0.8em; }
strong { font-weight: inherit; }
.note { color: var(--quiet); }

ul { list-style: none; margin: 0; padding: 0; }
li { text-wrap: pretty; }
li { margin-bottom: 0.3em; }
li:last-child { margin-bottom: 0; }
li ul { margin-top: 0.05em; }
li li {
  color: var(--quiet);
  padding-left: 1.1em;
  position: relative;
}
li li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.74em;
  width: 0.5em;
  border-top: 1px solid currentColor;
}
li li { margin-bottom: 0; }

/* A ledger row: date on the left, entry in the middle, result on the right */
.ledger li {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr) auto;
  column-gap: 1rem;
  align-items: baseline;
}
.ledger .when {
  color: var(--quiet);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.ledger .kind { margin-left: 0.6rem; color: var(--quiet); }
.ledger .result {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ledger .result.pending { color: var(--quiet); }
.after { margin-top: 0.8em; }

/* Portrait beside the opening paragraph */
.portrait {
  float: right;
  width: 7.5rem;
  height: 7.5rem;
  margin: 0.25rem 0 0.75rem 1.5rem;
  border-radius: 50%;
  object-fit: cover;
}
.intro::after { content: ""; display: block; clear: both; }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}
a:hover { color: var(--green); text-decoration-color: currentColor; }
a:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
  border-radius: 2px;
}

footer {
  margin-top: 3rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  color: var(--quiet);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* Photos and video. A figure holds one photo, one video, or one embed.
   A gallery sets figures side by side. */
/* The build wraps each <img> in <picture> to offer smaller copies. The wrapper takes no part in the layout. */
picture { display: contents; }
.media { margin: 0; }
.media img, .media video, .media iframe, .slot {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 3px;
  background: var(--wash);
}
.media img, .media video { height: auto; }
.media.embed iframe { aspect-ratio: 16 / 9; }
.media figcaption {
  margin-top: 0.4rem;
  color: var(--quiet);
  font-size: 0.875rem;
}
.media.lead { margin-bottom: 1.5rem; }
.media.narrow { max-width: 24rem; }
.gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.1rem;
}
.gallery.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.gallery img, .gallery video { aspect-ratio: 3 / 2; object-fit: cover; }
.gallery.three img, .gallery.three video { aspect-ratio: 4 / 5; }
.gallery.three.land img { aspect-ratio: 3 / 2; }
.gallery figcaption a, .credits a { color: inherit; }
.credits { margin-top: 0.6rem; font-size: 0.875rem; }
.content > .media, .content > .gallery { margin-top: 1.5rem; }
/* An empty place waiting for a file */
.slot {
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 2;
  color: var(--quiet);
  font-size: 0.875rem;
}
.gallery.three .slot { aspect-ratio: 4 / 5; }
.slot.wide-slot { aspect-ratio: 16 / 9; }

/* Inner pages */
.inner h1 { font-size: 1.75rem; }
.inner .top { padding-bottom: 0.6rem; }

/* Books and movies: a small cover, then the title, who made it, and one line */
.shelf li {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr);
  column-gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}
.shelf .cover img, .shelf .slot {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 2px;
  background: var(--wash);
  font-size: 0.6875rem;
}
.shelf .slot { display: grid; }
.shelf .cover { text-decoration: none; }
.shelf .kind { margin-left: 0.6rem; color: var(--quiet); }
.shelf p { margin-top: 0.1rem; }
/* The cover on a book or movie page, beside the notes */
.media.cover {
  float: right;
  width: 9.5rem;
  margin: 0.25rem 0 1rem 2rem;
}
.media.cover img, .media.cover .slot { aspect-ratio: 2 / 3; object-fit: cover; }

/* Long reading pages: chapter titles in the serif, a little more air between lines */
.prose p { line-height: 1.62; }
.prose section + section { margin-top: 3.25rem; }
.prose h2 {
  margin-bottom: 0.7rem;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink);
}
.prose h2.label {
  margin-bottom: 0.45rem;
  font-family: var(--sans);
  font-size: 1em;
  font-weight: 400;
  line-height: 1.5;
  color: var(--quiet);
}
.prose section > .media { margin: 1.5rem 0; }
.prose section > .media:last-child { margin-bottom: 0; }
.prose figcaption a { color: inherit; }
.prose .plain li { margin-bottom: 0.35em; }
.prose .plain + p { margin-top: 0.9em; }
.prose .small { font-size: 0.9375rem; color: var(--quiet); }
.prose .small a { color: inherit; }
.prose .note + .plain { margin-top: 0.7rem; }
.prose .small + .media { margin-top: 1.25rem; }
/* A tall picture that sits beside the text on wide screens */
.aside-figure { max-width: 15rem; }
.side .toc { display: none; }

/* Journal entries */
.entry + .entry { margin-top: 2rem; }
.entry .media { margin-top: 0.9rem; max-width: 30rem; }
.pictures { margin-top: 2.5rem; font-size: 0.875rem; }
.splits { max-width: 17rem; }
.splits li { grid-template-columns: 6.5rem 0 auto; justify-content: space-between; }

@media (max-width: 34rem) {
  body { font-size: 1rem; }
  h1 { font-size: 1.75rem; }
  .inner h1 { font-size: 1.5rem; }
  .kana { display: block; margin: 0.25rem 0 0; }
  .ledger li { grid-template-columns: 5.75rem minmax(0, 1fr) auto; column-gap: 0.75rem; }
  .portrait { width: 5.5rem; height: 5.5rem; margin-left: 1rem; }
  .ledger .kind { display: block; margin-left: 0; }
  .gallery, .gallery.three { gap: 0.5rem; }
  .media.cover { width: 6rem; margin-left: 1rem; }
  /* Numbered steps need only a narrow first column on a phone */
  .ledger.steps li { grid-template-columns: 1.4rem minmax(0, 1fr) auto; }
  /* Three landscape photos with credits are too small side by side; short captions can keep the row */
  .gallery.three.land:not(.keep) { grid-template-columns: 1fr; gap: 1rem; }
  .shelf .kind { display: block; margin-left: 0; }
}

/* Wide screens: the text takes eight parts, the section links take two */
@media (min-width: 62rem) {
  .page {
    max-width: 66rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    display: grid;
    grid-template-columns: minmax(0, 8fr) minmax(0, 2fr);
    column-gap: 4.5rem;
  }
  /* Inner pages: text keeps a reading width, photos use the full column */
  .inner .content p, .inner .ledger:not(.splits), .inner .plain { max-width: 40rem; }
  .inner .top { padding-bottom: 1.6rem; }
  .inner .side { padding-top: 0; }
  .side .toc { display: flex; }
  .prose .aside-figure { float: right; width: 15rem; margin: 0.3rem 0 1rem 2rem; }
  .prose section { clear: both; }
  .intro .note { font-size: 1.0625rem; }
  .top { grid-column: 1; grid-row: 1; padding-bottom: 2rem; }
  .content { grid-column: 1; grid-row: 2; }
  .side {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    position: sticky;
    top: 2.5rem;
    gap: 1.3rem;
    padding: 0.55rem 0 0;
  }
  .side .group { flex-direction: column; gap: 0.3rem; }
  .intro p { font-size: 1.25rem; line-height: 1.45; }
  .portrait { width: 9.5rem; height: 9.5rem; margin: 0.35rem 0 1rem 2rem; }
}

/* Figures between paragraphs inside a section */
section > p + .media, section > ul + .media, section > p + .gallery, section > ul + .gallery,
section > .media + .media { margin-top: 1.25rem; }
section > .media + p, section > .gallery + p, section > .media + ul, section > .gallery + ul { margin-top: 1.1rem; }
/* Screens of an app or a website get a hairline so pale edges do not melt into the page */
.media.screen img { border: 1px solid color-mix(in srgb, var(--line) 45%, transparent); }
section > p + ul.plain { margin-top: 0.6em; }
section > p + .ledger { margin-top: 0.6em; }
/* A picture that is a link: the caption carries the underline, the picture dims a little on hover */
.media figcaption a { color: inherit; }
.media a:hover img { opacity: 0.88; }
.media a img { transition: opacity 0.15s; }

/* Notes: each one is built around a diagram. The diagrams are SVG drawn in the page's own colors,
   so they follow light and dark. Each has two layouts: across for wide screens, downward for narrow. */
.diagram { margin: 1.75rem 0 0; }
.diagram svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--sans); }
.diagram .wide { display: none; }
.diagram .narrow { max-width: 22rem; }
.diagram .narrow .t { font-size: 14.5px; }
.diagram .narrow .s, .diagram .narrow .v, .diagram .narrow .lane { font-size: 12.5px; }
.diagram .narrow .n text { font-size: 11px; }
.diagram figcaption { margin-top: 0.9rem; color: var(--quiet); font-size: 0.875rem; max-width: 40rem; }
.diagram .box { fill: none; stroke: var(--line); stroke-width: 1; }
.diagram .key { fill: color-mix(in srgb, var(--green) 9%, transparent); stroke: var(--green); stroke-width: 1.5; }
.diagram .flow { fill: none; stroke: var(--ink); stroke-width: 1.25; stroke-linejoin: round; }
.diagram .head, .diagram .dot { fill: var(--ink); }
.diagram .t { fill: var(--ink); font-size: 16px; }
.diagram .s, .diagram .v, .diagram .lane { fill: var(--quiet); font-size: 13px; }
.diagram .k { fill: var(--green); }
.diagram .n circle { fill: var(--paper); stroke: var(--quiet); stroke-width: 1; }
.diagram .n text { fill: var(--quiet); font-size: 12px; }
.post .when { color: var(--quiet); }
.post section.intro + .diagram + section { margin-top: 2.75rem; }
@media (min-width: 62rem) {
  .diagram .wide { display: block; }
  .diagram .narrow { display: none; }
}
/* In a note, a numbered list wears the same circled numbers as the diagram */
.post .ledger.steps li { grid-template-columns: 1.9rem minmax(0, 1fr); column-gap: 0.6rem; margin-bottom: 0.7em; }
.post .ledger.steps .when {
  width: 1.3rem;
  height: 1.3rem;
  border: 1px solid var(--quiet);
  border-radius: 50%;
  font-size: 0.75rem;
  line-height: 1.2rem;
  text-align: center;
}
.post .ledger.steps .kind { display: block; margin-left: 0; }
/* More marks for diagrams and charts in notes */
.diagram .dash { stroke-dasharray: 4 4; }
.diagram .keyline { stroke: var(--green); stroke-width: 1.75; }
.diagram .head.k { fill: var(--green); }
.diagram .grid { stroke: var(--line); stroke-width: 1; opacity: 0.45; }
.diagram .link { stroke: var(--line); stroke-width: 2; }
.diagram .ring { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }
.diagram .fill, .diagram .hit { fill: var(--green); }
.diagram .cell { fill: var(--paper); stroke: var(--green); stroke-width: 1; }
.diagram .cell.plain { stroke: var(--line); }
.diagram .pos { fill: var(--quiet); font-size: 11.5px; }
.diagram .pos.on { fill: var(--paper); }
.diagram .big { fill: var(--ink); font-size: 22px; font-family: var(--serif); font-weight: 500; }
.diagram .t.small { font-size: 14.5px; }
.diagram .narrow .t.small { font-size: 13.5px; }
/* The list of notes: the title on one line, what it is about on the next */
.ledger.list li { margin-bottom: 0.75em; }
.ledger.list .kind { display: block; margin-left: 0; }
/* The world map on the home page. Land comes from Natural Earth (public domain). */
.diagram.map { margin: 2.5rem 0 0; }
.diagram .store { position: absolute; width: 0; height: 0; }
.diagram.map .land { fill: color-mix(in srgb, var(--line) 36%, var(--paper)); }
.diagram.map .trade { fill: none; stroke: var(--green); stroke-width: 1.5; }
.diagram.map .place { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.diagram.map svg a { fill: inherit; text-decoration: underline; text-decoration-color: var(--line); }
.diagram.map svg a:hover { fill: var(--green); }
.diagram.map .narrow { max-width: none; }
.diagram.map .narrow .t { font-size: 11.5px; }
.diagram.map .narrow .s { font-size: 10.5px; }
.diagram.map .narrow .trade { stroke-width: 1.1; }
.diagram.map .narrow .place { stroke-width: 1.5; }
.diagram.map .d { fill: var(--quiet); font-size: 11.5px; }
.diagram.map .narrow .d { font-size: 10px; }
.diagram.map .trade { stroke-width: 1.3; }
.diagram.map .narrow .trade { stroke-width: 1; }
/* Each line sits on a paper-colored casing so that crossing lines stay apart */
.diagram.map .halo { fill: none; stroke: var(--paper); stroke-width: 4.5; opacity: 0.9; }
.diagram.map .trade { stroke-width: 1.8; stroke-linecap: round; }
.diagram.map .narrow .halo { stroke-width: 3; }
.diagram.map .narrow .trade { stroke-width: 1.3; }

/* The Japanese pages (the ja/ folder). The same layout, set for Japanese text: a Japanese face behind each
   Latin one, more room between the lines, and line breaks that follow the rules of Japanese. */
html[lang="ja"] {
  --serif: "Newsreader", "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --sans: "Hanken Grotesk", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", "Yu Gothic", "Noto Sans JP", sans-serif;
}
html[lang="ja"] body { line-height: 1.75; line-break: strict; }
html[lang="ja"] h1 { line-height: 1.35; letter-spacing: 0.03em; }
html[lang="ja"] h2 { line-height: 1.75; }
html[lang="ja"] .prose p { line-height: 1.9; }
html[lang="ja"] .prose h2 { line-height: 1.45; letter-spacing: 0.02em; }
html[lang="ja"] .prose h2.label { line-height: 1.75; letter-spacing: 0; }
html[lang="ja"] li li::before { top: 0.875em; }
/* The name in Latin letters beside the Japanese name */
.roman {
  margin-left: 0.75rem;
  color: var(--quiet);
  font-size: 0.9375rem;
  letter-spacing: 0;
  white-space: nowrap;
}
@media (max-width: 34rem) {
  .roman { display: block; margin: 0.15rem 0 0; }
}
@media (min-width: 62rem) {
  html[lang="ja"] .intro p { font-size: 1.1875rem; line-height: 1.8; }
  html[lang="ja"] .inner .content p, html[lang="ja"] .inner .ledger:not(.splits), html[lang="ja"] .inner .plain { max-width: 39rem; }
}
