@font-face {
  font-display: fallback;
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 400;
  src: url("/assets/fonts/OpenSans-Regular.ttf");
}

@font-face {
  font-display: fallback;
  font-family: "Open Sans";
  font-style: italic;
  font-weight: 400;
  src: url("/assets/fonts/OpenSans-Italic.ttf");
}

@font-face {
  font-display: fallback;
  font-family: "Open Sans";
  font-style: bold;
  font-weight: 700;
  src: url("/assets/fonts/OpenSans-Bold.ttf");
}

* {
  box-sizing: border-box;
}

html {
  background: #c18b2a;
  background-attachment: fixed;
  background-image: url(/assets/textureGold.jpeg);
}

/*
 * Body
 */

body {
  color: var(--color-text);
  counter-reset: h2;
  display: grid;
  grid-template-columns: 100%;
  justify-content: center;
  margin: 0;
  min-height: 100vh;
  padding: 0;
  --color-canvas-subtle: hsl(47deg 53% 95%);
  --color-rule: #cfc294;
  --color-text: rgb(51, 51, 51);
}

/*
 * Stock elements
 */

h1,
h2,
h3 {
  text-wrap: balance;

  a {
    visibility: hidden;
  }

  &:hover {
    a {
      visibility: visible;
    }
  }
}

h1 {
  font-size: 2.25rem;
}

h2 {
  font-size: 1.8rem;
  margin-top: 2em;
}

h3 {
  font-size: 1.4rem;
}

.numberHeadings h2:before {
  counter-increment: h2;
  content: counter(h2) ". ";
}

/* .numberHeadings h3:before {
  counter-increment: h3;
  content: counter(h2) "." counter(h3) ". ";
} */

.markdown-body > :first-child,
.markdown-body > p:first-of-type {
  margin-top: 0;
}

.error {
  background: #fff5f7;
  border: 1px solid red;
  margin-bottom: 1em;
  padding: 1em;
  --color-canvas-subtle: transparent;
}

.error pre {
  padding: 0;
  margin: 16px 0 0 0;
}

#logo {
  align-self: start;
  display: none;
}

header {
  align-content: center;
  align-items: center;
  border-bottom: 1px solid var(--color-rule);
  color: #222e3e;
  display: grid;
}

header h1 {
  margin: 0;
}

.supertitle {
  font-weight: bold;
  margin: 0;
}

.subtitle {
  font-style: italic;
  margin-top: 0;
}

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

blockquote {
  border: none;
  color: inherit;
  padding: 0.5rem 2rem;
}

table {
  /* Try to prevent tables from overflowing page width on mobile */
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

tr {
  vertical-align: top;
}

td {
  vertical-align: top;
}

th, td {
  padding-right: 1em;
}

figure {
  display: grid;
  gap: 3rem;
  justify-items: center;
  margin: 3rem 0;
}

.constrain {
  max-height: 50vmax;
  max-width: 50vmax;
}

figcaption {
  font-size: smaller;
  font-style: italic;
}

svg {
  height: inherit;
  max-height: 100%;
  max-width: 100%;
}

/*
 * Design elements
 */
#page {
  background: var(--color-page);
  box-shadow: 0 0 20px rgb(0 0 0 / 50%);
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: auto 1fr;
  margin: 1rem 0 5rem;
  max-width: 100%;
  --color-page: #fafafa;
  --grid-gap: 1rem;
  --grid-padding-horizontal: 1rem;
  --grid-padding-vertical: 1rem;
  --side-nav-width: 0;
}

#pageContent {
  display: grid;
  gap: var(--grid-gap);
  grid-template-columns: 100%;
  grid-template-rows: repeat(3, auto) 1fr;
  padding: var(--grid-padding-vertical) var(--grid-padding-horizontal);
  --grid-padding-vertical: 2rem;
}

img.origami {
  height: 100px; /* For Safari */
  margin: 0;
  max-height: 100px;
}

/*
 * Code
 */

pre {
  overflow: auto;
  font-size: 85%;
  line-height: 1.45;
  background-color: var(--color-canvas-subtle);
  border-radius: 6px;
  padding: 16px;
}
td pre {
  margin: 0;
  padding: 0;
}

pre,
code {
  font-family: "Consolas", "Menlo", "Courier New", "Courier", monospace;
}

code.language-console,
code.language-console .hljs-meta {
  color: #333;
  font-weight: normal;
}

code.language-console span {
  color: #222;
  font-weight: bold;
}

pre.step {
  color: #555;
}

pre.step b {
  color: black;
  font-weight: bold;
}

/*
 * Navigation
 */

#topNav {
  background: #222e3e;
  background-image: url(/assets/textureIndigo.jpeg);
  box-shadow: 0px 5px 0.5rem 0px rgb(0 0 0 / 25%);
  display: grid;
  grid-column: 1 / span 2;
  grid-template-columns: var(--side-nav-width) 1fr;
  padding: var(--grid-padding-vertical) var(--grid-padding-horizontal);
}

#topNav a {
  color: #eee;
}

#homeContainer {
  visibility: hidden;
}

.optional {
  display: none;
}

#navBar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

#topNav a,
nav a {
  text-decoration: none;
  white-space: nowrap;
}

#topNav a:hover,
nav a:hover {
  text-decoration: underline;
}

#topNav [aria-current] {
  color: white;
  font-weight: bold;
}

#sideBar {
  grid-column: 1; /* Baffled as to why this is necessary. */
}

#sideBar:has(li) {
  border-bottom: 1px solid var(--color-rule);
}

#sideBar > ul {
  display: grid;
  gap: 0 1em;
  grid-template-columns: repeat(auto-fit, minmax(150px, max-content));
  justify-content: space-between;
  padding-left: 0;
}

#sideBar li {
  list-style: none;
  margin-bottom: 0.5rem;
}

#sideBar [aria-current] {
  color: inherit;
}

#sideBar .noLink {
  color: #bbb;
}

.video16x9 {
  aspect-ratio: 16 / 9;
  margin-top: 1em;
  margin-bottom: 1em;
  width: 100%;
}

/*
 * Code
 */
.hljs {
  background: inherit;
  color: inherit;
}

code.hljs {
  padding: 0;
}

pre code.hljs {
  padding: 0;
}

/* Approximate more recent GitHub styling for inline code */
code {
  background-color: var(--color-canvas-subtle);
  white-space: nowrap;
}
code:not(pre code) {
  border-radius: 6px;
  font-size: 85%;
  margin: 0;
  padding: .2em .4em;
}
pre code {
  white-space: pre-wrap;
}
p code {
  white-space: break-spaces;
}

/*
 * Architecture block diagram
 */
.blocks {
  display: grid;
  float: right;
  font-size: smaller;
  gap: 0.25rem;
  grid-template-columns: auto auto;
  margin-bottom: 1rem;
  margin-left: 1rem;
}

.blocks a {
  align-content: center;
  background: var(--color-rule);
  border: 1px solid var(--color-rule);
  color: white;
  display: grid;
  justify-content: center;
  padding: 0.25rem 0.5rem;
  text-decoration: none;
}

.blocks a:hover {
  filter: brightness(1.1);
}

.blocks [aria-current] {
  background: white;
  color: var(--color-text);
  font-weight: bold;
}

.blocks .optional {
  display: none;
}

.blocks a[href="/async-tree/"],
.blocks a[href="/builtins/"],
.blocks a[href="/pattern/"] {
  grid-column: 1 / span 2;
}

/*
 * Side-by-side layouts
 */
.sideBySide {
  align-items: center;
  display: grid;
  gap: 2rem;
  grid-template-areas:
    "figure1"
    "caption1"
    "figure2"
    "caption2"
    "figure3"
    "caption3";
  justify-items: center;
  margin: 3em 0;
}

.sideBySide figure:nth-of-type(1) {
  grid-area: figure1;
}
.sideBySide figure:nth-of-type(2) {
  grid-area: figure2;
}
.sideBySide figure:nth-of-type(3) {
  grid-area: figure3;
}

.sideBySide figcaption:nth-of-type(1) {
  grid-area: caption1;
}
.sideBySide figcaption:nth-of-type(2) {
  grid-area: caption2;
}
.sideBySide figcaption:nth-of-type(3) {
  grid-area: caption3;
}

.sideBySide figure {
  margin: 0;
}

/*
 * Generated graph SVGs on page
 */
g.graph polygon[fill="white"] {
  /* fill: transparent; */
}

g.node ellipse[fill="none"],
g.node polygon[fill="none"] {
  fill: white;
}

.screenshot {
  border: 1px solid #ddd;
  max-height: 350px;
  max-width: 50%;
}

/*
 * Tutorial
 */
.tutorialStep:before {
  content: "➤";
  color: var(--color-rule);
}

/*
 * Responsive queries
 */

@media (min-width: 900px) {
  body {
    grid-template-columns: auto;
  }

  pre {
    white-space: pre-wrap;
  }

  #page {
    grid-template-columns: minmax(100%, 1000px);
    grid-template-rows: auto 1fr;
    --grid-gap: 1rem;
    --grid-padding-horizontal: 2rem;
    --side-nav-width: 200px;
  }

  #topNav {
    gap: var(--grid-gap);
  }

  #homeContainer {
    visibility: visible;
  }

  .optional {
    display: contents;
  }
  
  #pageContent {
    /* Given above columns for #page, not sure why we also need to specify 800px here. */
    grid-template-columns: var(--side-nav-width) minmax(auto, 800px);
    grid-template-rows: auto 1fr;
    --grid-padding-vertical: 2rem;
  }

  img.origami {
    align-self: center;
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.25));
    height: 100px;
    margin: 1rem 0;
    max-width: 90%;
  }

  #navBar a[href="/"],
  #sideBar a[href="/"] {
    display: none;
  }

  #sideBar {
    grid-column: auto;
  }

  #sideBar ul {
    display: block;
    padding-left: 20px;
  }

  #sideBar:has(li) {
    border-bottom: none;
  }

  header h1 {
    margin-bottom: inherit;
  }

  .blocks {
    grid-template-columns: 1fr 1fr;
    font-size: inherit;
  }
  .blocks a {
    padding: 0.5rem 1rem;
  }

  .sideBySide {
    grid-template-areas:
      "figure1 figure2 figure3"
      "caption1 caption2 caption3";
  }

  .split2to3 {
    grid-template-columns: 2fr 3fr;
  }

  figure {
    margin: 3rem 3rem 3rem 0;
  }

  .fullWidth {
    position: relative;
    left: calc(0px - var(--side-nav-width));
    width: calc(100% + var(--side-nav-width));
  }

  .tutorialStep:before {
    margin-left: -1.5em;
    position: absolute;
  }
}
