:root {
  --body-width: 992px;
  --text-width: 620px;
  --bg-body: #dedad6;
  --bg-block: #d6d1cc;
  --border-color: #999;
  --box-shadow: 5px 5px 5px #ccc;
}

* {
  box-sizing: border-box;
}

body {
  max-width: var(--body-width);
  min-height: calc(100vh - 3em);
  background-color: var(--bg-body);
  margin: auto;
  padding: 1em;
  line-height: 1.5;
  position: relative;
  display: flex;
  flex-direction: column;
  counter-reset: pageNumber;
}

/* header and footer areas */
.nav-top,
.single .meta-line,
.nav-bottom,
.post-nav {
  display: flex;
  justify-content: space-between;
}

.home+footer>.nav-bottom {
  display: block;
}

.nav-top {
  margin-bottom: 1em;
  border-bottom: 1px solid;
}

.logo {
  font-weight: bold;
  margin-top: .5rem;

  img {
    display: none;
    max-height: 4rem;
    position: absolute;
    top: 2em;
  }
}

.menu {
  text-transform: uppercase;

  span {
    display: inline-block;
    margin: .5rem 0 0 .5em;
  }

  .active {
    border-bottom: 5px solid;
    margin-bottom: -5px;
  }

  .optional {
    display: none;
  }
}

footer {
  text-align: center;
  margin-top: 2rem;
}

.menu-bottom a+a::before {
  content: " · ";
}

/* code */
pre code {
  display: block;
  padding: 1em;
  overflow-x: auto;

  &:not([class]) {
    background: none;
  }
}

pre code,
img[src$="#border"] {
  border: 1px solid var(--border-color);
  box-shadow: var(--box-shadow);
}

code {
  hyphens: none;
}

pre code,
pre code:hover {
  white-space: pre-wrap;
  word-break: break-all;
}

/* misc elements */
.main,
.home {
  hyphens: auto;
}

.main,
.home,
.terms {
  flex-grow: 1;
}

a {
  text-decoration: none;
  border-bottom: 1px dashed;
  color: initial;
}

@media (hover: hover) and (pointer: fine) {
  :not(.logo)>a:hover {
    position: relative;
    inset: 1px 0 0 1px;
  }
}

nav a,
footer a,
.archive a,
sup a {
  border-bottom: none;
}

.anchor {
  &:not(:hover > *) {
    display: none;
  }

  &>a::before {
    content: "#";
  }
}

.single .main {
  h2 {
    border-bottom: 1px solid var(--border-color);
    font-variant: small-caps;
    text-align: center;
  }

  h3 {
    font-size: 1.3em;
    font-variant: small-caps;
    text-align: center;
  }
}

.main>p:first-of-type::first-line {
  font-variant: small-caps;
  letter-spacing: .05em;
  font-size: 1.1em;
}

.main>p:first-of-type::first-letter {
  font-size: 1.5em;
  padding: 0 .1em 0 0;
  float: left;
  line-height: .9em;
  font-weight: bold;
  margin-top: .1em;
}

li {
  margin: 4px 0;
}

hr {
  border-style: dashed;
  color: var(--border-color);
}

img,
iframe,
video {
  max-width: 100%;
}

#TableOfContents {
  background-color: var(--bg-block);
  padding: .5em;

  &>ul {
    margin: 0 auto;

    &>li>ul li {
      margin-right: 2em;
    }
  }
}

blockquote,
.toc-list,
.toc-list ul {
  border-left: 2px solid var(--border-color);
  padding-left: 1em;
}

.single blockquote {
  background: var(--bg-block);
  border-left-width: 5px;
  padding: 3px 1em 3px;
}

.post-nav {
  margin-top: 1rem;

  span {
    width: calc(50% - 1em);

    &+span {
      text-align: right;
    }
  }
}

table {
  min-width: 50%;
  margin: auto;
  border-top: 1px solid #aaa;
  border-bottom: 1px solid #aaa;

  thead th {
    border-bottom: 1px solid var(--border-color);
  }

  th,
  td {
    padding: 5px;
  }

  thead,
  tfoot,
  tr:nth-child(even),
  code {
    background: var(--bg-block);
  }
}

/* metadata */
.toc-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5em;
}

.dots {
  border-bottom: 2px dotted var(--border-color);
  margin: 0 .5em .5em;
  min-width: 10rem;
  flex-grow: 1;
}

.page-num {
  counter-increment: pageNumber;

  &::before {
    content: counter(pageNumber);
  }
}

.toc-list,
.toc-list ul {
  list-style: none;
  margin-left: 1em;
}

.toc-line,
.subtitle,
.meta-line {
  font-weight: normal;
}

.toc-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5em;
}

.meta-line {
  display: inline;
  margin-left: 1em;
  color: #666;
  font-style: normal;
}

.toc-line .dots {
  display: none;
}

.toc-line .page-num {
  display: none;
}

.toc-line>a {
  font-style: normal;
}

.toc-line .meta-line {
  font-style: normal;
}

.author+.date::before {
  content: " / ";
}

h1.title>a {
  font-style: italic;
}

h1.title {
  margin-top: 1em;
}

h1.title::before {
  content: "";
  font-style: normal;
  font-weight: normal;
  font-size: 2em;
  color: var(--border-color);
  opacity: .1;
  position: absolute;
  inset: -.15em 0;
  z-index: -1;
}

.small,
.term,
.footnotes,
li li {
  font-size: .9em;
}

.footnotes>hr {
  max-width: 20em;
  margin-left: 0;
}

.terms,
#TableOfContents>ul>li>ul {
  display: flex;
  flex-wrap: wrap;
}

.terms li,
.term {
  margin-left: 2em;
}

.term-cat+.term-tag::before {
  content: " · ";
}

@media (min-width: 768px) {
  body {
    padding: 3.5em 2.5em;
  }

  .main {
    margin: auto;
    width: var(--text-width);
  }

  .fullwidth {
    width: calc(min(100vw, var(--body-width)) - 5rem);
    margin-left: calc(50% + 2.5rem - min(100vw, var(--body-width)) / 2);
  }

  .crop-h,
  .crop-v,
  .crop-c {
    position: absolute;
    z-index: -1;
  }

  .crop-h {
    inset: 2em 0;
    border-top: 1px solid;
    border-bottom: 1px solid;
  }

  .crop-v {
    inset: 0 2em;
    border-left: 1px solid;
    border-right: 1px solid;
  }

  .crop-c {
    inset: 1em;
    border: 1.5em solid var(--bg-body);
  }

  .menu {
    margin-left: 2em;
  }

  .menu span {
    margin-left: 1em;
  }

  h1.title::before {
    font-size: 6em;
    inset: 0;
  }

  .logo img,
  .menu .optional {
    display: inline-block;
  }

  .twocolumn {
    columns: 2;
  }
}

@media only screen and (min-width: 992px) {
  body {
    min-height: calc(100vh - 5em);
    margin: 2em auto;
  }

  .home {
    padding: 0 2em;
  }

  h1.title {
    margin-top: 2em;

    &::before {
      font-size: 9em;
      inset: -.1em 0;
    }
  }

  pre code {
    white-space: pre;
  }
}

html,
img,
video,
iframe {
  filter: invert(1);
}

.main img {
  border: 1px solid var(--border-color);
  box-shadow: var(--box-shadow);
}

.blog .main {
  margin-left: 0;
  width: 100%;
  max-width: none;
}

.blog .toc-line {
  margin-left: 0;
  padding-left: 0;
}

.blog.single .main {
  margin: auto;
  width: var(--text-width);
  max-width: var(--text-width);
}

@media (max-width: 767px) {
  body {
    font-size: 1.2em;
  }

  .main {
    width: 100%;
    margin: 0;
  }

  .menu {
    font-size: 1.2em;
  }

  h1.title {
    font-size: 2em;
  }

  .blog .main {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }

  .blog .toc-line {
    margin-left: 0;
    padding-left: 0;
  }

  .blog.single .main {
    width: 100%;
    max-width: 100%;
  }
}

.post-wrapper {
  display: grid;
  grid-template-columns: 1fr minmax(0, var(--text-width)) 1fr;
  gap: 2em;
}

.post-sidebar {
  grid-column: 1 / 2;
  justify-self: end;
}

@media (min-width: 992px) {
  .post-sidebar {
    padding-top: 3.5em;
  }
}

.post-content {
  grid-column: 2 / 3;
  width: 100%;
}

.post-toc {
  position: sticky;
  top: 1.5em;
  width: 224px;

}

.post-toc nav ul {
  list-style: none;
  list-style-type: none;
  padding-left: 0;
  margin: 0;
}

.post-toc nav > ul > li {
  padding-top: 0.4em;
}

.post-toc nav > ul > li > a {
  font-weight: 600;
  color: #000000b5;
}

.post-toc nav ul ul {
  padding-left: 0.75em;
  margin-top: 0.4em;
  margin-left: 0.25em;
  border-left: 1px solid var(--border-color);
}

.post-toc nav a {
  display: block;
  padding: 0.2em 0;
  font-size: 0.82em;
  color: #000000b5;
  border-bottom: none;
}

.post-toc nav a:hover {
  color: #000000;
}

@media (max-width: 991px) {
  .post-sidebar {
    display: none;
  }

  .post-wrapper {
    display: block;
  }

  .post-content {
    margin: 0;
  }
}