:root {
  --tex-size: 11.5pt;
  --tex-baseline: 1.58;
  --tex-textwidth: 100%;
  --tex-serif: "STIX Two Text", "Latin Modern Roman", "PT Serif", "Times New Roman", serif;
  --tex-ink: #12100e;
  --tex-ink-muted: #4a4540;
  --tex-paper: #fffaf4;
  --tex-block-bg: #f6f0e6;
  --tex-block-line: #c8bfb0;
  --page-a4-w: 21cm;
  --page-pad-y: 2.1cm;
  --page-pad-x: 2cm;
  --page-sheet-w: min(
    calc(100vw - 1.3rem),
    var(--page-a4-w),
    calc((100dvh - 5.5rem) * 210 / 297)
  );
  --focus: #5c4a8a;
}

html[lang="ar"] {
  --tex-serif: "Noto Naskh Arabic", "STIX Two Text", serif;
}

html[lang="hi"] {
  --tex-serif: "Noto Serif Devanagari", "STIX Two Text", serif;
}

html[lang="ja"] {
  --tex-serif: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-variant-east-asian: proportional-width;
}

html[lang="ar"] .language-nav,
html[lang="hi"] .language-nav,
html[lang="ja"] .language-nav {
  text-transform: none;
  letter-spacing: 0.06em;
}

* {
  box-sizing: border-box;
}

html[dir="rtl"] {
  direction: rtl;
}

html[dir="rtl"] .site-top {
  flex-direction: row-reverse;
}

html[dir="rtl"] .language-nav {
  justify-content: flex-start;
}

html[dir="rtl"] .language-nav::before {
  order: 2;
}

html[dir="rtl"] .page-body p,
html[dir="rtl"] .page-prelude p,
html[dir="rtl"] .tex-block p {
  text-align: right;
}

html[dir="rtl"] .tex-block {
  border-left: 0.4pt solid var(--tex-block-line);
  border-right: 2.5pt solid #5c4a8a;
}

html[dir="rtl"] .abstract-block {
  border-right-color: #0a8f8a;
}

html {
  background: #08060f;
  scroll-behavior: smooth;
}

body {
  position: relative;
  margin: 0;
  font-family: var(--tex-serif);
  font-size: var(--tex-size);
  line-height: var(--tex-baseline);
  color: var(--tex-ink);
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
}

#plasma-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.52;
  mix-blend-mode: screen;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.03) 0,
      rgba(0, 0, 0, 0.03) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(ellipse 90% 70% at 50% 100%, rgba(0, 0, 0, 0.55), transparent 58%),
    radial-gradient(ellipse 70% 45% at 15% 10%, rgba(123, 63, 242, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 40% at 88% 18%, rgba(0, 220, 200, 0.1), transparent 48%);
}

.site-top {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: nowrap;
  align-items: baseline;
  gap: 0.75rem;
  width: var(--page-sheet-w);
  margin: 0 auto 0.45rem;
  padding: 0.5rem var(--page-pad-x) 0.45rem;
  overflow: hidden;
  background: var(--tex-paper);
  border: 1px solid #ddd5c8;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 8px 28px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  border-bottom: 0.4pt solid var(--tex-ink);
}

.home-link {
  font-family: var(--tex-serif);
  font-size: 0.9em;
  font-variant: small-caps;
  font-weight: 500;
  color: var(--tex-ink-muted);
  text-decoration: none;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.language-nav {
  display: flex;
  flex-wrap: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.15rem 0.55rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  font-size: 0.78em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tex-ink-muted);
}

.language-nav::before {
  content: "";
  flex: 1 1 auto;
  min-width: 0.5rem;
  border-bottom: 0.4pt dotted #c8bfb0;
  margin: 0 0.15rem 0.2em;
  opacity: 0.85;
}

.language-link {
  font-family: var(--tex-serif);
  font-size: 1em;
  font-weight: 500;
  color: var(--tex-ink-muted);
  text-decoration: none;
  white-space: nowrap;
}

.language-link:hover {
  color: var(--tex-ink);
}

.language-link[aria-current="page"] {
  color: var(--tex-ink);
  font-weight: 600;
  text-decoration: none;
  box-shadow: inset 0 -0.4pt 0 var(--tex-ink);
}

.home-link:focus-visible,
.language-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.book {
  position: relative;
  z-index: 2;
  isolation: isolate;
  padding: 0.85rem 0.65rem 2rem;
}

.book-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 1rem);
  min-height: calc(100dvh - 1rem);
  padding: 0.5rem 0 1.75rem;
  scroll-snap-align: start;
  scroll-snap-stop: normal;
}

.book-page--title {
  scroll-snap-align: none;
}

.page-sheet {
  width: var(--page-sheet-w);
  aspect-ratio: 210 / 297;
  height: auto;
  margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x);
  background: var(--tex-paper);
  border: 1px solid #ddd5c8;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.5) inset,
    0 12px 40px rgba(0, 0, 0, 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
}

.page-inner {
  flex: 1;
  max-width: var(--tex-textwidth);
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.book-page--title .page-sheet {
  justify-content: center;
}

.article-head {
  margin: 0;
  padding: 0 0 1.1em;
  border-bottom: 0.4pt solid var(--tex-ink);
  text-align: center;
}

.article-head h1 {
  font-size: 1.42em;
  font-weight: 600;
  line-height: 1.18;
  margin: 0 0 0.55em;
  text-wrap: balance;
}

.article-subtitle {
  font-size: 1.02em;
  font-weight: 400;
  font-style: italic;
  line-height: 1.35;
  margin: 0 0 0.9em;
  color: var(--tex-ink-muted);
  text-wrap: balance;
}

.article-meta {
  font-size: 0.96em;
  color: var(--tex-ink-muted);
  margin: 0;
  line-height: 1.45;
}

.page-chapter {
  font-size: 0.8em;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tex-ink-muted);
  margin: 0 0 0.35em;
  text-align: center;
}

.page-title {
  font-size: 1.14em;
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 1.05em;
  padding-bottom: 0.6em;
  text-align: center;
  border-bottom: 0.4pt solid #c8bfb0;
  text-wrap: balance;
}

.page-body {
  flex: 1;
}

.page-body p,
.page-prelude p {
  margin: 0;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  text-wrap: pretty;
  orphans: 3;
  widows: 3;
}

.page-body p + p,
.page-prelude p + p {
  margin-top: 0.82em;
}

.page-prelude {
  margin-top: 1.2em;
}

.tex-block {
  margin: 0.95em 0;
  padding: 0.75em 0.9em 0.8em;
  background: var(--tex-block-bg);
  border: 0.4pt solid var(--tex-block-line);
  border-left: 2.5pt solid #5c4a8a;
}

.tex-block:first-child {
  margin-top: 0;
}

.tex-block:last-child {
  margin-bottom: 0;
}

.tex-block-label {
  display: block;
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5c4a8a;
  margin: 0 0 0.45em;
}

.tex-block p {
  margin: 0;
  font-size: 0.98em;
  text-align: left;
}

.tex-block p + p {
  margin-top: 0.55em;
}

.abstract-block {
  border-left-color: #0a8f8a;
}

.abstract-block .tex-block-label {
  color: #0a6f6b;
}

.term {
  font-style: italic;
}

html.lang-ruby code,
html.lang-elixir code,
html.lang-cucumber code {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", "Consolas", monospace;
  font-size: 0.9em;
  font-style: normal;
  letter-spacing: -0.01em;
}

html.lang-ruby .term,
html.lang-elixir .term,
html.lang-cucumber .term {
  font-style: normal;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", "Consolas", monospace;
}

html.lang-ruby .tex-block-label,
html.lang-elixir .tex-block-label,
html.lang-cucumber .tex-block-label {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", "Consolas", monospace;
  letter-spacing: 0.02em;
}

.source-doc .page-body,
.source-doc .page-prelude {
  margin-top: 0.5rem;
}

.source-file-label {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", "Consolas", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
  opacity: 0.72;
}

.source-file-label a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

.source-block {
  margin: 0;
  padding: 0;
  overflow-x: auto;
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", "Consolas", monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  tab-size: 2;
  white-space: pre;
  text-wrap: wrap;
}

.source-block code {
  font-family: inherit;
  font-size: inherit;
  font-style: normal;
}

.notation {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.page-footer {
  margin-top: auto;
  padding-top: 1.25em;
  font-size: 0.88em;
  color: var(--tex-ink-muted);
  text-align: center;
  letter-spacing: 0.06em;
}

.page-num::before {
  content: "— ";
}

.page-num::after {
  content: " —";
}

@media (min-width: 768px) {
  html {
    scroll-snap-type: y proximity;
  }

  .book {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

@media (max-width: 767px) {
  :root {
    --page-pad-y: clamp(1.3rem, 5vw, 2.1cm);
    --page-pad-x: clamp(1.05rem, 4.5vw, 2cm);
  }

      .book {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
      }

  .page-body p,
  .page-prelude p,
  .tex-block p {
    text-align: left;
  }

  .book-page {
    min-height: auto;
    padding-bottom: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
    background: #1a1228;
  }

  #plasma-canvas {
    display: none;
  }
}

@page {
  size: A4;
  margin: 2.54cm 2cm;
}

@media print {
  html {
    background: #fff;
    scroll-snap-type: none;
  }

  #plasma-canvas,
  body::after,
  .site-top {
    display: none !important;
  }

  .book {
    padding: 0;
  }

  .book-page {
    min-height: auto;
    padding: 0;
    page-break-after: always;
    break-after: page;
  }

  .book-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .page-sheet {
    width: auto;
    aspect-ratio: auto;
    height: auto;
    border: none;
    box-shadow: none;
    max-width: none;
    padding: 0;
  }
}
