:root {
  /* Font Styles */
  --font-family: sans-serif;
  --font-family-mono: monospace;

  --font-size-body: 1.375rem;
  --font-size-primary: 1.25rem;
  --font-size-secondary: 1.125rem;
  --font-size-tertiary: 1rem;
  --font-size-quaternary: 0.875rem;
  --font-size-h1: 2.25rem;
  --font-size-h2: 1.625rem;
  --font-size-h3: 1.5rem;
  --font-size-h4: 1.375rem;

  /* Colors */
  --color-background-dark: #121212;
  --color-background-primary: #ffffff;
  --color-background-secondary: #2d2d2d;
  --color-background-tertiary: #424242;
  --color-border-blockquote: #aaaaaa;
  --color-border-primary: #616161;
  --color-border-secondary: #757575;
  --color-border-tertiary: #9e9e9e;
  --color-text-primary: #121212;
  --color-text-secondary: #eeeeee;
  --color-text-tertiary: #e0e0e0;
  --color-text-dark: #9e9e9e;
  --color-text-darker: #757575;
  --color-text-accent: #006eff;
  --color-accent-light-blue: #3793dd;
  --color-accent-blue: #2271b1;
  --color-accent-dark-blue: #135e96;
  --color-accent-light-red: #ff5d5e;
  --color-accent-red: #b32d2e;

  /* Effects */
  --box-shadow-faint: 1px 0 14px 0 rgb(0, 0, 0, 0.04);
  --box-shadow-light: 0 0 8px rgb(0 0 0 / 15%);
 
  /* Components */
  --height-site-header: 2.5rem;

  /* Root Settings */
  -moz-tab-size: 4;
  tab-size: 4;
  color-scheme: dark; /* Keep consistent with iframe */
}

@media (prefers-reduced-motion: no-preference) {
  :root {
    scroll-behavior: smooth;
  }
}

@media screen and (max-width: 768px) {
  :root {
    --font-size-body: 1rem;
    --font-size-primary: 1.125rem;
    --font-size-secondary: 1rem;
    --font-size-tertiary: 0.875rem;
    --font-size-quaternary: 0.75rem;
    --font-size-h1: 1.5rem;
    --font-size-h2: 1.375rem;
    --font-size-h3: 1.25rem;
    --font-size-h4: 1.125rem;
  }
}

/* Resets and Top-Level Structure */
/* Setting box-sizing on all elements makes it easier to use content-box on container elements */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  -webkit-tap-highlight-color: transparent;
}

body {
  color: var(--color-text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  font-kerning: auto;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: var(--color-background-primary);
}

main {
  flex-grow: 1;
}

iframe {
  border: 0;
  color-scheme: dark; /* Keep consistent with :root */
}

/* Text */
.typography {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Headings */
h1, .h1,
h2, .h2,
h3, .h3,
h4, .h4,
h5, .h5,
h6, .h6 {
  color: var(--color-text-primary);
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 0.75rem;
}

h1, .h1 {
  font-size: var(--font-size-h1);
}

h2, .h2 {
  font-size: var(--font-size-h2);
}

h3, .h3 {
  font-size: var(--font-size-h3);
}

h4, .h4 {
  font-size: var(--font-size-h4);
}

h5, .h5,
h6, .h6 {
  font-size: 1em;
}

/* p */
p {
  margin: 0 0 1.5rem;
}

p:last-child {
  margin: 0;
}

/* a */
a {
  color: var(--color-accent-blue);
  text-decoration: none;
  transition: color 0.15s ease-in-out;
}

a:hover,
a:focus {
  color: var(--color-accent-light-blue);
}

.typography a {
  color: var(--color-accent-blue);
  text-decoration: underline;
  transition: color 0.15s linear, text-decoration 0.15s linear;
}

.typography a:hover,
.typography a:focus {
  color: var(--color-accent-light-blue);
}

/* Inline Markup */
b,
strong {
  font-weight: bolder;
}

small {
  font-size: 0.875em;
}

mark {
  padding: 0.1875em;
}

sub,
sup {
  font-size: 0.75em;
  line-height: 0;
  vertical-align: baseline;
  position: relative;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.5em;
}

abbr[title] {
  -webkit-text-decoration: underline dotted;
  text-decoration: underline dotted;
  -webkit-text-decoration-skip-ink: none;
  text-decoration-skip-ink: none;
  cursor: help;
}

/* Block Markup */
hr {
  color: inherit;
  margin: 1.5rem 0;
  border: 0;
  border-top: 1px solid;
  opacity: 0.25;
}

ul,
ol {
  padding-left: 1.5rem;
}

ul,
ol,
dl {
  margin: 0 0 1.5rem;
}

ul:last-child,
ol:last-child,
dl:last-child {
  margin: 0;
}

ul ul
ol ol
ul ol
ol ul {
  margin: 0.75rem 0 0;
}

.typography li:not(:last-child) {
  margin: 0 0 0.25rem;
}

.typography ul ul li:first-child {
  margin: 0.25rem 0;
}

dt {
  font-weight: 700;
}

dd {
  margin-bottom: 0.5rem;
  margin-left: 0;
}

blockquote {
  margin: 0 0 1.5rem;
  padding: 0.5rem 1rem;
  border-left: 2px solid var(--color-border-blockquote);
}

blockquote p:not(:last-child) {
  margin: 0 0 0.75rem;
}

details {
  display: block;
}

summary {
  display: list-item;
  cursor: pointer;
}

/* pre, code, kbd */
pre,
code,
kbd,
samp {
  font-family: var(--font-family-mono);
  font-size: 1em;
}

pre {
  font-size: 0.875em;
  display: block;
  margin: 0 0 1.5rem;
  overflow: auto;
}

pre code {
  color: inherit;
  font-size: inherit;
  word-break: normal;
}

code {
  color: var(--color-text-lighter);
  font-size: 0.875em;
  word-wrap: break-word;
}

a > code {
  color: inherit;
}

kbd {
  color: var(--color-background-primary);
  font-size: 0.875em;
  padding: 0.1875rem 0.375rem;
  background-color: var(--color-text-primary);
  border-radius: 0.25rem;
}

kbd kbd {
  font-size: 1em;
  padding: 0;
}

/* Elements */
/* Images */
img,
svg {
  line-height: 1;
  vertical-align: middle;
}

.img-fluid {
  max-width: 100%;
  height: auto;
}

figure {
  line-height: 1;
  margin: 0 0 1.5rem;
}

figcaption {
  color: var(--color-text-lighter);
  font-size: var(--font-size-secondary);
  line-height: 1.5;
}

/* Buttons and Inputs */
button {
  border-radius: 0;
}

button:focus:not(:focus-visible) {
  outline: 0;
}

.btn {
  --btn-color: var(--color-text-secondary);
  --btn-color-accent: transparent;
  --btn-background: none;
  --btn-border: none;
  --btn-border-radius: 6px;
  color: var(--btn-color);
  fill: var(--btn-color);
  text-align: center;
  display: inline-block;
  vertical-align: middle;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  background: var(--btn-background);
  border: var(--btn-border);
  border-radius: var(--btn-border-radius);
  transition: color .15s ease-in-out, fill .15s ease-in-out, background .15s ease-in-out, border-color .15s ease-in-out;
}

.btn:hover {
  --btn-color: var(--color-text-primary);
  color: var(--btn-color);
  fill: var(--btn-color);
}

.btn svg {
  pointer-events: none;
  user-select: none;
}

.btn-round {
  --btn-border-radius: 100%;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

@media screen and (hover: hover) and (pointer: fine) {
  .btn-icon:hover {
    --btn-background: var(--color-background-tertiary);
  }
}

.btn-icon.btn-toggle.active {
  --btn-background: var(--color-border-primary);
}

input,
button,
select,
optgroup,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
}

button,
select {
  text-transform: none;
}

[role=button] {
  cursor: pointer;
}

button,
[type=button],
[type=reset],
[type=submit] {
  -webkit-appearance: button;
}

button:not(:disabled),
[type=button]:not(:disabled),
[type=reset]:not(:disabled),
[type=submit]:not(:disabled) {
  cursor: pointer;
}

#site-header {
  color: var(--color-background-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  height: var(--height-site-header);
  padding: 0 0.5rem;
  position: sticky;
  top: 0;
  background: var(--color-background-dark);
  z-index: 99999;
}

#site-header .btn {
  width: 2rem;
  height: 2rem;
  padding: 0.5rem;
}

#site-header .btn:hover,
#site-header .btn:focus {
  --btn-color: var(--color-background-primary);
}

#site-header .btn:first-child {
  margin-right: auto;
}

#site-menu-wrap,
#settings-menu-wrap {
  font-size: var(--font-size-secondary);
  visibility: hidden;
  position: fixed;
  height: calc(100vh - var(--height-site-header));
  top: var(--height-site-header);
  bottom: 0;
  left: 0;
  right: 0;
  transition-delay: 0s, 0.3s;
  transition: background 0.3s ease, visibility 0.3s ease-in-out;
  z-index: 99999;
}

#site-menu-wrap.show {
  visibility: visible;
  background: rgb(0 0 0 / 85%);
  transition-delay: 0s;
}

#settings-menu-wrap.show {
  visibility: visible;
  transition-delay: 0s;
}

#site-menu,
#settings-menu {
  color: var(--color-background-primary);
  overflow-y: auto;
  position: absolute;
  top: 0;
  left: -350px;
  max-width: 100%;
  width: 350px;
  height: calc(100vh - var(--height-site-header));
  padding-top: 1px;
  background: var(--color-background-dark);
  transition: transform 0.3s ease-in-out;
  will-change: transform;
}

#settings-menu {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  left: unset;
  right: -250px;
  width: 250px;
  padding: 1rem;
}

.show #site-menu {
  transform: translateX(350px);
  transition-delay: 0s;
}

.show #settings-menu {
  transform: translateX(-250px);
  transition-delay: 0s;
}

#site-menu ul {
  font-size: unset;
  font-weight: unset;
  display: initial;
  list-style: none;
  padding: 0;
}

#site-menu a {
  font-weight: 500;
  color: var(--color-background-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  transition: 0.15s color ease-in-out, 0.15s background ease-in-out;
}

#site-menu a:hover,
#site-menu a:focus {
  background: var(--color-accent-dark-blue);
  color: var(--color-background-primary);
}

#site-menu a.book {
  gap: 1rem;
}

#site-menu a img {
  width: 100%;
  max-width: 72px;
}

@media screen and (max-width: 500px) {
  #site-menu {
    width: 100%;
    left: -100%;
  }

  #settings-menu {
    width: 100%;
    right: -100%;
  }

  .show #site-menu {
    transform: translateX(100%);
  }

  .show #settings-menu {
    transform: translateX(-100%);
  }

  #site-menu a {
    padding: 0.75rem 0.75rem 0.75rem 1rem;
  }
}

#site-menu::-webkit-scrollbar {
  display: none;
}

#table-of-contents-wrap {
  width: 600px;
  max-width: 100%;
  height: calc(100vh - var(--height-site-header) - 3rem);
  position: fixed;
  top: calc(1.5rem + var(--height-site-header));
  right: 3rem;
  z-index: 5;
}

#table-of-contents-wrap:not(.show) {
  display: none;
}

#table-of-contents {
  overflow-y: auto;
  height: 100%;
  padding: 3rem;
  background: var(--color-background-primary);
  border: 3px solid var(--color-background-dark);
  border-radius: 6px;
  box-shadow: 0 0 6px rgb(0 0 0 / 30%), 0 0 12px rgb(0 0 0 / 25%);
  overscroll-behavior-y: contain;
}

@media screen and (max-width: 768px) {
  #table-of-contents-wrap {
    width: 100%;
    height: calc(100vh - var(--height-site-header));
    top: var(--height-site-header);
    right: 0;
  }

  #table-of-contents {
    padding: 1rem;
    border: unset;
    box-shadow: unset;
  }
}

.reader {
  display: grid;
  grid-template-columns: 1fr;
  position: relative;
}

.reader.two-pane {
  grid-template-columns: 1.4fr 1fr;
}

.pane {
  max-height: calc(100vh - var(--height-site-header));
}

.reader.two-pane > #pane-left {
  overflow-y: scroll;
}

.reader:not(.two-pane) > #pane-left {
  max-width: 850px;
  max-height: unset;
  margin: 0 auto;
}

#pane-right {
  font-size: var(--font-size-secondary);
  display: flex;
  flex-direction: column;
}

.reader:not(.two-pane) > #pane-right {
  display: none;
}

.pane-item {
  padding: 3rem;
  position: relative;
}

.pane-item:not(.show) {
  display: none;
}

#pane-right > .pane-item {
  flex-grow: 1;
  overflow-y: scroll;
}

#pane-right > .pane-item:not(:last-child) {
  border-bottom: 2px solid var(--color-background-dark);
}

#footnotes {
  flex-basis: 70%;
  flex-shrink: 0;
}

@media screen and (max-width: 768px) {
  #site-header {
    position: sticky;
    top: 0;
  }

  .reader,
  .reader.two-pane {
    grid-template-columns: 1fr;
  }

  #pane-left {
    max-height: unset;
  }

  .reader.two-pane > #pane-left {
    margin-bottom: 30vh;
  }

  #pane-right {
    background: var(--color-background-primary);
    border-top: 2px solid var(--color-background-dark);
  }

  .pane-item {
    padding: 1rem;
  }

  #pane-right > .pane-item {
    overflow-y: auto;
    height: 30vh;
    position: fixed;
    bottom: 0;
    background: var(--color-background-primary);
    border-top: 2px solid var(--color-background-dark);
    border-bottom: unset!important;
  }
}
