:root {
  --background: #2b2b2b;
  --control: #eeeeee;
  --control-hover: rgba(255, 255, 255, 0.08);
  --control-active: rgba(228, 0, 43, 0.16);
  --jeffrey-red: #e4002b;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--background);
}

body {
  position: fixed;
  inset: 0;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#reader {
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 4vmin;
  overflow: hidden;
  touch-action: manipulation;
}

#book {
  display: inline-grid;
  grid-template-rows: auto auto;
  gap: clamp(0.65rem, 1.4vmin, 1.05rem);
  justify-items: stretch;
}

#spread-frame {
  position: relative;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

#spread-frame.cover-front::after,
#spread-frame.cover-back::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: var(--cover-page-width);
  height: var(--cover-page-height);
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.36);
  pointer-events: none;
  z-index: 0;
}

#spread-frame.cover-front::after {
  right: calc((100% - var(--spread-width)) / 2);
}

#spread-frame.cover-back::after {
  left: calc((100% - var(--spread-width)) / 2);
}

#spread {
  position: relative;
  z-index: 1;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.36);
  user-select: none;
  -webkit-user-drag: none;
  cursor: pointer;
  touch-action: manipulation;
}

#spread-frame.cover-front #spread,
#spread-frame.cover-back #spread {
  box-shadow: none;
}

#controls {
  width: 100%;
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 3rem;
  grid-template-areas: "prev dots next";
  align-items: center;
  min-height: 3.25rem;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#prev {
  grid-area: prev;
}

#next {
  grid-area: next;
}

#dots {
  grid-area: dots;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.28rem, 0.58vw, 0.48rem);
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dot {
  box-sizing: border-box;
  display: block;
  width: clamp(0.58rem, 0.9vw, 0.86rem);
  height: clamp(0.58rem, 0.9vw, 0.86rem);
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dot.read {
  border-color: transparent;
  background: rgba(245, 245, 245, 0.96);
}

.dot.current {
  border-color: transparent;
  background: var(--jeffrey-red);
  box-shadow: none;
}

.nav-button {
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: transparent;
  color: var(--control);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.5rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.nav-glyph {
  display: block;
  line-height: 1;
  transform: translateY(-3px);
  pointer-events: none;
}

.nav-button:hover {
  background: var(--control-hover);
  color: #ffffff;
}

.nav-button:active {
  background: var(--control-active);
  color: var(--jeffrey-red);
}

.nav-button.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .dot {
    cursor: pointer;
    transition: transform 80ms linear, background-color 80ms linear, border-color 80ms linear;
  }

  .dot:hover {
    transform: scale(1.18);
    border-color: #ffffff;
  }

  .dot.current:hover {
    border-color: var(--jeffrey-red);
  }
}

@media (prefers-reduced-motion: no-preference) {
  #spread {
    transition: opacity 80ms linear;
  }

  #spread.loading {
    opacity: 0.001;
  }
}

@media (max-width: 720px), (max-height: 660px) {
  #spread {
    box-shadow: 0 0.55rem 1.35rem rgba(0, 0, 0, 0.32);
  }

  #spread-frame.cover-front::after,
  #spread-frame.cover-back::after {
    box-shadow: 0 0.55rem 1.35rem rgba(0, 0, 0, 0.32);
  }

  #controls {
    grid-template-columns: 3rem minmax(0, 1fr) 3rem;
    grid-template-areas: "prev dots next";
    min-height: 3.25rem;
  }

  #dots {
    gap: clamp(0.18rem, 0.72vw, 0.34rem);
    overflow: visible;
  }

  .dot {
    width: clamp(0.48rem, 1.65vw, 0.72rem);
    height: clamp(0.48rem, 1.65vw, 0.72rem);
  }
}
