:root {
  --bg: rgb(30, 40, 50);
  --text: #e7f5ff;
  --mid: #9aa;
  --near-bg: hsl(from var(--bg) h s calc(l + 10));
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: rgb(245, 245, 245);
    --text: #1a1a1a;
    --mid: #889;
    --near-bg: #daeffa;
  }
}

body {
  margin: 0;
  padding: 0;
  font-family: "Alegreya", serif;
  font-optical-sizing: auto;
  font-style: normal;
  font-size: 1.5rem;
  line-height: 1.6;
  position: relative;
  background-color: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  min-height: 100vh;

  &::before {
    content: '';
    position: fixed;
    z-index: -1;
    inset: 0;
    background: radial-gradient(circle at 50% 75%, var(--bg) 70%, var(--near-bg));
    filter: url(#grainy);

    @media(prefers-color-scheme: light) {
      filter: url(#grainy) opacity(0.2);
    }
  }
}

/* Noise bg courtesy of Ana Tudor's great example here:
 * https://codepen.io/thebabydino/pen/abjpEbz
 */
svg[height='0'] {
  position: fixed
}

a {
  color: inherit;
  text-underline-offset: 2px;
  text-decoration-color: var(--mid);
}

a:hover {
  color: var(--pop);
}

.nav-wrapper {
  position: sticky;
  top: 16px;
  margin: 1rem;
  display: flex;
  justify-content: space-between;
  z-index: 10;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.not-sr-only {
  position: static;
  width: auto;
  height: auto;
  padding: 0;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

.site-nav,
.searchbar,
.searchbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.site-nav,
.searchbar,
.searchbar-wrapper button,
.searchbar .search-results {
  padding: 0.5rem 1rem;
  background-color: rgba(from var(--bg) r g b / 0.75);
  backdrop-filter: blur(3px);
  border: solid 1px var(--mid);
  width: fit-content;
}

.site-nav .content-types {
  display: contents;
}

.site-nav a {
  text-decoration-color: var(--near-bg);
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--pop);
}

.searchbar {
  border: 1px var(--mid) solid;
  padding: 0;
  margin: 0.5rem;
}

.searchbar-wrapper button {
  display: none;
}

.searchbar input {
  background-color: var(--near-bg);
  color: var(--text);
  border: solid var(--near-bg) 1px;
  border-radius: 0;
  padding: 0.5rem;
}

.searchbar input::placeholder {
  color: var(--text);
}

.searchbar .search-results {
  position: absolute;
  top: calc(100% + 1rem);
  right: 0;
  max-height: 50vh;
  overflow: auto;
  width: max-content;
  max-width: 400px;
}

.search-results ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
}

.search-results li {
  padding: 0.25rem 0.5rem;
  border: solid 1px var(--near-bg);
}

.search-results li:hover {
  color: var(--pop);
}

.search-results a {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}

.search-results a span {
  color: var(--mid);
}

@media (max-width: 768px) {
  .nav-wrapper {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
  }

  .site-nav {
    border-width: 2px 2px 0 0;
    flex-grow: 1;
    padding-inline-start: 1rem;
    overflow: auto;
  }

  .site-nav .content-types {
    display: flex;
    gap: 1rem;
    flex-grow: 1;
    overflow: auto;
    padding-inline: 1rem;
    margin: 0;
  }

  .searchbar-wrapper {
    display: contents;
  }

  .searchbar-wrapper button {
    color: currentColor;
    display: block;
    padding: 0 0.5rem;
    border-width: 2px 0 0 0;

    & svg {
      display: block;
      width: 3em;
    }
  }

  .searchbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    width: 100%;
    border: solid var(--text);
    border-width: 2px 0 0 0;
  }

  .searchbar input {
    display: block;
    padding: 0.5rem;
    font-size: 1rem;
    width: calc(100% - 1rem);
  }

  .searchbar .search-results {
    top: auto;
    bottom: 100%;
    right: 1rem;
    width: calc(100% - 4rem);
    margin: 1rem;
  }
}

main {
  margin: 0.5rem;
  padding: 0.5rem;
}

main img {
  max-width: 100%;
}

h2 small {
  font-weight: normal;
  color: var(--mid);
}

.grid {
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.grid-card,
.grid-card a>p {
  list-style: none;
  display: contents;
}

.grid-card a {
  position: relative;
  text-decoration: none;
  margin: 0;
  display: grid;
  border: solid 1px var(--near-bg);
  padding: 0.5rem 1rem;
}

.grid-card a:hover {
  border-color: var(--pop);
}

.grid-card .item-info {
  display: contents;
}

.grid-card img.book-cover {
  max-width: 100%;
  max-height: 300px;
  display: block;
  margin-inline: auto;
  margin-bottom: 0.5rem;
  transform-style: preserve-3d;
  transform: rotate3d(0, 1, 0, 15deg) skewY(7.5deg) scale(0.9);
}

.grid-card.books a {
  border-color: transparent;
  overflow: hidden;
}

.grid-card.books .item-info {
  position: absolute;
  display: block;
  background-color: rgba(from var(--bg) r g b / 0.35);
  backdrop-filter: blur(2px);
  top: auto;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem 1rem;
  border-radius: 8px 8px 0 0;
  border-top: solid 1px var(--mid);
  transform-style: preserve-3d;

  /* transitioning properties */
  transform: skewY(7.5deg) translateY(1rem);
  opacity: 0;
  transition: opacity 0.08s ease-out,
    transform 0.11s ease-out,
    background-color 0.08s ease-out;
}

.grid-card.books:focus-within .item-info,
.grid-card.books:hover .item-info {
  transform: skewY(7.5deg);
  opacity: 1;
  background-color: rgba(from var(--bg) r g b / 0.85);
}

.grid-card .meta-wrapper {
  align-self: flex-end;
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.8em;
  color: var(--mid);
}

.grid-card img.growth-icon {
  display: block;
  margin: 0;
  width: 36px;
}

.grid-card .meta {
  display: flex;
  flex-direction: column;
}

footer {
  margin: 0 1rem;
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  font-size: 0.75rem;
  border: solid 1px;
  border-bottom: none;
}