@font-face {
  font-family: "EB Garamond";
  src: url("./eb-garamond.woff2") format("woff2-variations");
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
}

@font-face {
  font-family: "EB Garamond";
  src: url("./eb-garamond-italic.woff2") format("woff2-variations");
  font-style: italic;
  font-weight: 400 800;
  font-display: swap;
}

@font-feature-values "EB Garamond" {
  @styleset {
    fleurons: 4;
    q: 6;
  }
}

@font-face {
  font-family: "Monaspace";
  src: url("./monaspace.woff2") format("woff2-variations");
  font-weight: 200 800;
  font-style: oblique -11deg 0deg;
  font-display: swap;
}

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

*:not(dialog) {
  margin: 0;
}

html {
  font-size: clamp(125%, calc(125% + 4 * (100vw - 390px) / 320), 150%);
  font-family: "EB Garamond", serif;
  font-kerning: normal;
  font-variant-ligatures: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-weight: 400;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: subpixel-antialiased;
  background-color: var(--bg);
  color: var(--text);
}

body {
  padding: calc(env(safe-area-inset-top) + 1rem) calc(env(safe-area-inset-right) + 1rem)
    calc(env(safe-area-inset-bottom) + 2rem) calc(env(safe-area-inset-left) + 1rem);
  width: 100%;
  max-width: 100%;
  line-height: 1.4;
}

body:has(p .katex) {
  line-height: 1.45;
}

nav {
  visibility: visible;
  max-width: calc(650px + 6.8rem);
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin: 0 auto;
  position: sticky;
  top: 1rem;
  z-index: 1;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

main {
  width: 100%;
  margin: auto;
  container: main / inline-size;
}

main > *,
main > .together > *,
main > details > * {
  visibility: visible;
  max-width: 650px;
  margin-left: auto;
  margin-right: auto;
}

main pre:has(> code) {
  min-width: min(calc(100vw - 2.66rem - env(safe-area-inset-left) - env(safe-area-inset-right)), 650px);
  width: min(calc(100vw - 2.66rem - env(safe-area-inset-left) - env(safe-area-inset-right)), 800px);
  max-width: fit-content;
}

main p:has(.katex-display) {
  min-width: min(calc(100vw - 2.66rem - env(safe-area-inset-left) - env(safe-area-inset-right)), 650px);
  width: fit-content;
  max-width: calc(100vw - 2.66rem - env(safe-area-inset-left) - env(safe-area-inset-right));
  margin: 0 auto;
}

input,
button,
textarea,
select {
  font: inherit;
}

p {
  text-wrap: pretty;
  margin: 0.9rem auto;
}

blockquote {
  margin: 1rem auto;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
  font-weight: 400;
  font-size: 1em;
}

h1 {
  margin: 0;
  font-size: 2em;
  font-weight: 400;
  line-height: 0.9;
  font-variant-caps: all-small-caps;
}

:is(h1, h2, a.page, .entry) .sensitive {
  font-variant-caps: normal;
  font-feature-settings:
    "c2sc" 1,
    "pcap" 1;
}

:is(h1, h2, a.page, .entry) .sensitive .smcp {
  font-variant-caps: all-small-caps;
  font-size: 0.9em;
  font-weight: 450;
}

header {
  display: flex;
  flex-direction: column;
  gap: 0.25em;
  margin: 0.5em auto 1.2em auto;
  padding-bottom: 0.6em;
  border-bottom: 0.5px solid;
  letter-spacing: 0.05em;
}

header.index {
  flex-direction: column-reverse;
  gap: 0;
  text-align: center;
  border-bottom: 0;
  padding-bottom: 0;
  margin-top: 1.5em;
  user-select: none;
  -webkit-user-select: none;
}

header.index h1 {
  letter-spacing: 0;
  line-height: 1.01;
  text-transform: none;
  font-variant-caps: normal;
  font-variant-alternates: styleset(q);
}

nav.index {
  position: fixed;
  right: 1rem;
}

nav.index + main header {
  margin-top: 1.5em;
}

@media (min-width: 820px) {
  nav {
    position: fixed;
    right: 1rem;
  }

  header {
    margin-top: 1.5em;
  }
}

header p {
  font-variant-caps: all-small-caps;
  margin: 0;
  text-wrap: balance;
}

.break {
  display: none;
}

header h1 .break {
  display: table;
}

h2 {
  margin: 1.4rem auto 0.9rem auto;
  font-variant-caps: all-small-caps;
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0.05em;
  font-size: 1.2em;
}

h3 {
  margin: 1.4rem auto 0.9rem auto;
  font-style: italic;
  font-size: 1.1em;
}

h4,
h5,
h6 {
  margin: 0.9rem auto;
  font-weight: 480;
}

code {
  font-family: "Monaspace", "Monaspace", ui-monospace, monospace;
  font-size: 0.778em;
  font-weight: 360;
  font-variant-ligatures: contextual;
}

strong {
  font-weight: 670;
}

math,
math * {
  display: initial;
  user-select: none;
  -webkit-user-select: none;
}

.katex {
  font-size: 0.96em;
}

.katex-display .katex {
  font-size: 1.05em;
  padding: 0.15rem;
}

.katex-display > .katex {
  overflow: auto hidden;
  scrollbar-width: thin;
}

.katex-display {
  will-change: transform;
}

.katex-display > .katex > .katex-html > .tag {
  position: fixed;
  user-select: none;
  -webkit-user-select: none;
}

.katex-display:not(:has(.tag)) > .katex {
  white-space: normal;
}

.katex-display:has(.tag) .katex-html::after {
  content: "\200b";
  /* could tailor-fit server-side for every equations (incl. responsive variants) */
  padding: 0.8em;
}

.katex .frac-line {
  border-radius: 0.5em;
}

@media (min-width: 375px) {
  .no-wrap {
    white-space: nowrap;
  }
}

blockquote {
  padding: 0.6rem 1rem;
  background-color: var(--blockquote-bg);
  border-left: 5px solid var(--blockquote-border);
}

blockquote :first-child {
  margin-top: 0;
}

blockquote :last-child {
  margin-bottom: 0;
}

hr {
  margin: 1.6em auto;
  border: none;
  overflow: visible;
  color: color-mix(in srgb, var(--text) 70%, var(--bg) 30%);
}

hr::before {
  content: "\2619";
  display: block;
  line-height: 0;
  text-align: top;
  width: fit-content;
  margin: 0 auto;
}

a {
  --color: color-mix(in srgb, var(--text) 70%, var(--bg) 30%);
  --icon: url("icon/link.svg");
  color: var(--color);
  text-decoration: underline 0.5px solid color-mix(in srgb, var(--text) 40%, var(--bg) 60%);
}

a.page {
  --color: var(--text);
  --icon: url("icon/document.svg");
  font-variant-caps: all-small-caps;
  letter-spacing: 0.05em;
  margin-right: 0.05em;
  text-decoration: none;
}

a.page::before,
a:not(.page)::after {
  content: "";
  display: inline-block;
  background-color: var(--color);
  mask: var(--icon) no-repeat 50% 50%;
  mask-size: cover;
}

a::after {
  width: 0.65em;
  height: 0.65em;
  vertical-align: text-top;
  margin-top: 0.1em;
  margin-left: 0.05em;
}

a.page::before {
  width: 0.62em;
  height: 0.62em;
  margin-right: 0.15em;
  margin-left: 0.1em;
  margin-bottom: -0.05em;
}

a.url {
  overflow-wrap: anywhere;
}

a:not(:is(.index-link, :has(.sensitive))):hover,
a:hover .sensitive {
  text-decoration: underline 0.5px solid var(--color);
}

a.index-link {
  display: block;
  line-height: 1;
  text-align: center;
  width: 2rem;
  margin: 2rem auto 0 auto;
  font-size: 1.2em;
  font-variant-alternates: styleset(fleurons);
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
}

a.index-link::after {
  content: none;
  display: none;
}

details {
  display: contents;
}

details summary {
  user-select: none;
  -webkit-user-select: none;
  margin: 1rem auto;
}

ol,
ul {
  padding-left: 1em;
}

@supports (hanging-punctuation: first) {
  /* for Safari as content doesn't work and dot isn't removed ugh */
  ol,
  ul {
    padding-left: 1.3em;
  }
}

li::marker {
  font-variant-numeric: oldstyle-nums; /* tabular by default */
  color: var(--text);
}

ul > li::marker {
  content: "\2022\2002";
  display: inline-block;
}

ol > li::marker {
  content: counter(list-item) "\2002";
}

.together {
  display: contents;
}

*:has(+ .together) {
  margin-bottom: 0;
}

.together + * {
  margin-top: 0;
}

@media (min-width: 768px) {
  ol,
  ul {
    padding-left: 0;
  }

  .together:has(:is(ol, ul)) + * {
    margin-top: 0.2em;
  }
}

.mb {
  display: inline-block;
  margin-bottom: 0.9em;
}

#dark-mode {
  display: grid;
  width: max-content;
  user-select: none;
  -webkit-user-select: none;
  border: none;
  padding: 0;
}

@media print {
  #dark-mode {
    visibility: hidden;
  }
  /* TODO: Avoid breaking images and code blocks across pages. */
}

.katex:has(~ .katex-display),
#dark-mode input,
#dark-mode legend,
#dark-mode label span,
#share-link span {
  position: absolute;
  -webkit-clip-path: inset(50%);
  clip-path: inset(50%);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

#dark-mode label,
#share-link {
  border-radius: 5px;
  border: 1px solid var(--blockquote-border);
  background-color: var(--bg);
  user-select: none;
  -webkit-user-select: none;
}

#dark-mode label {
  padding: 0.37rem 0.65rem;
  grid-column: 1 / span 1;
  grid-row: 1 / span 1;
}

#share-link button {
  --icon: var(--icon-share);
  background: transparent;
  border: none;
  padding: 0.37rem 0.65rem;
}

#share-link.success button {
  --icon: var(--icon-share-success);
  --icon-color: green;
}

#share-link.error button {
  --icon: var(--icon-share-error);
  --icon-color: red;
}

#share-link.copy button {
  --icon: var(--icon-share-copy);
}

#dark-mode label::after,
#share-link button::after {
  content: "";
  background-color: var(--icon-color, var(--text));
  display: inline-block;
  mask: var(--icon) no-repeat 50% 50%;
  mask-size: cover;
  width: 1em;
  height: 1em;
  margin-bottom: -0.165rem;
}

#dark-mode [for="dark-system"]::after {
  --icon: var(--icon-system-theme);
}

@media (prefers-color-scheme: dark) {
  :root:has(#dark-mode [value="other"]:checked) {
    color-scheme: light;
  }

  :root:not(:has(#dark-mode [value="other"]:checked)) code.hljs {
    filter: brightness(0.9);
  }

  #dark-mode [for="dark-self"]::after {
    --icon: var(--icon-dark);
  }

  #dark-mode [for="dark-other"]::after {
    --icon: var(--icon-light);
  }

  #dark-mode [for="dark-self"] .light,
  #dark-mode [for="dark-other"] .dark {
    display: none;
  }
}

@media (prefers-color-scheme: light) {
  :root:has(#dark-mode [value="other"]:checked) {
    color-scheme: dark;
  }

  :root:has(#dark-mode [value="other"]:checked) code.hljs {
    filter: brightness(0.9);
  }

  #dark-mode [for="dark-self"]::after {
    --icon: var(--icon-light);
  }

  #dark-mode [for="dark-other"]::after {
    --icon: var(--icon-dark);
  }

  #dark-mode [for="dark-self"] .dark,
  #dark-mode [for="dark-other"] .light {
    display: none;
  }
}

#dark-mode.system:has(input#dark-system:checked) [for="dark-other"],
#dark-mode.system:has(input#dark-other:checked) [for="dark-self"],
#dark-mode.system:has(input#dark-self:checked) [for="dark-system"] {
  opacity: initial;
  z-index: 1;
}

#dark-mode.system:has(input#dark-system:checked:focus-visible) [for="dark-other"],
#dark-mode.system:has(input#dark-other:checked:focus-visible) [for="dark-self"],
#dark-mode.system:has(input#dark-self:checked:focus-visible) [for="dark-system"] {
  outline: 2px solid var(--text);
}

.diarytime > .line-block {
  text-align: center;
  width: fit-content;
  margin-left: auto;
  font-style: italic;
}

.diarytime {
  margin: 1em auto;
}

.book,
.poem,
.poem-text {
  margin: 0 auto;
}

.book {
  text-align: left;
}

.book :not(header, h1, h2, h3, h4, h5, h6, a, .poem-text p) {
  text-indent: var(--indent) each-line;
}

.book > p:first-of-type:not(:has(+ p > .dialogue)) {
  text-indent: 0;
}

@media (min-width: 525px) {
  .book :not(header, h1, h2, h3, h4, h5, h6, a, .poem-text p) {
    hyphens: auto;
    text-align: justify;
    text-justify: inter-word;
  }
}

.book p {
  margin: 0;
}

.n {
  hyphens: manual !important;
}

.poem,
.poem-text {
  width: fit-content;
}

.poem-text {
  hyphens: manual;
  text-align: left;
}

.poem-text p {
  text-indent: var(--indent) each-line hanging;
}

.book .poem-text {
  padding: 0 var(--indent);
}

:root {
  color-scheme: light dark;

  --bg: light-dark(#fffff8, black);
  --text: light-dark(#111, #ddd);
  --indent: clamp(1em, 4.6vw, 1.4em);

  --bg: light-dark(#fffff8, black);
  --text: light-dark(#111, #ddd);
  --blockquote-bg: light-dark(whitesmoke, #444444);
  --blockquote-border: light-dark(lightgray, #888888);
  --hr: color-mix(in srgb, var(--text) 55%, var(--bg) 45%);
  /* Code themes are Atom One Light and Atom One Dark
     with background colors slightly adjusted. */
  --code-base: light-dark(#fbf8f4, #282c34c0);
  --code-mono-1: light-dark(#383a42, #abb2bf);
  --code-mono-2: light-dark(#686b77, #818896);
  --code-mono-3: light-dark(#a0a1a7, #5c6370);
  --code-hue-1: light-dark(#0184bb, #56b6c2);
  --code-hue-2: light-dark(#4078f2, #61aeee);
  --code-hue-3: light-dark(#a626a4, #c678dd);
  --code-hue-4: light-dark(#50a14f, #98c379);
  --code-hue-5: light-dark(#e45649, #e06c75);
  --code-hue-5-2: light-dark(#c91243, #be5046);
  --code-hue-6: light-dark(#986801, #d19a66);
  --code-hue-6-2: light-dark(#c18401, #e6c07b);

  --icon-dark: url("./icon/moon.svg");
  --icon-light: url("./icon/sun.svg");
  --icon-system-theme: url("./icon/contrast.svg");
  --icon-share: url("./icon/share.svg");
  --icon-share-success: url("./icon/success.svg");
  --icon-share-error: url("./icon/error.svg");
  --icon-share-copy: url("./icon/copy.svg");
}

pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 0.7rem;
  border-radius: 0.4rem;
  line-height: 1.45;
}

code.hljs {
  padding: 3px 5px;
  border-radius: 3px;
}

.hljs {
  color: var(--code-mono-1);
  background: var(--code-base);
}
.hljs-comment,
.hljs-quote {
  color: var(--code-mono-3);
  font-style: italic;
}
.hljs-doctag,
.hljs-keyword,
.hljs-formula {
  color: var(--code-hue-3);
}
.hljs-section,
.hljs-name,
.hljs-selector-tag,
.hljs-deletion,
.hljs-subst {
  color: var(--code-hue-5);
}
.hljs-literal {
  color: var(--code-hue-1);
}
.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
  color: var(--code-hue-4);
}
.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-type,
.hljs-selector-class,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-number {
  color: var(--code-hue-6);
}
.hljs-symbol,
.hljs-bullet,
.hljs-link,
.hljs-meta,
.hljs-selector-id,
.hljs-title {
  color: var(--code-hue-2);
}
.hljs-built_in,
.hljs-title.class_,
.hljs-class .hljs-title {
  color: var(--code-hue-6-2);
}
.hljs-emphasis {
  font-style: italic;
}
.hljs-strong {
  font-weight: bold;
}
.hljs-link {
  text-decoration: underline;
}

.tree {
  margin: 0;
  padding: 0;
}

.tree li {
  list-style-type: none;
}

.tree li::marker {
  content: "";
}

.tree li p {
  font-size: 0.8em;
  color: var(--hr);
  margin: 0 0 0 0.8rem;
  line-height: 1.2;
  max-width: 480px;
}

.tree .entry {
  padding-top: 0.4em;
  padding-bottom: 0.4em;
  width: 100%;
  line-height: 0.9;
  user-select: none;
  -webkit-user-select: none;
  font-variant-caps: all-small-caps;
  text-wrap: balance;
}

.tree figure:has(.entry + *),
.tree figure:has(.entry + *) .entry {
  padding-bottom: 0.3em;
}

.tree .entry a {
  width: 100%;
  display: flex;
  gap: 0.15em;
}

.tree .entry a::before {
  margin-top: 0.24em;
  margin-right: 0;
  margin-left: 0;
}

.tree details {
  display: block;
}

.tree details details {
  margin-bottom: -0.5px;
}

.tree details > ul {
  margin-left: 0.5em;
}

.tree details > summary {
  display: block;
  letter-spacing: 0.05em;
  margin: 0;
  cursor: pointer;
}

.tree summary::-webkit-details-marker {
  display: none;
}

.tree details > summary::before {
  --icon: url("icon/folder.svg");
  content: "";
  display: inline-block;
  background-color: var(--hr);
  mask: var(--icon) no-repeat 50% 50%;
  mask-size: cover;
  width: 0.62em;
  height: 0.62em;
  vertical-align: middle;
  margin-right: 0.2em;
}

.tree details[open] > summary::before {
  --icon: url("icon/folder-open.svg");
}

.more {
  margin-top: 2em;
}

.more > figcaption {
  font-style: italic;
}

.message {
  font-style: italic;
  text-align: center;
}
