:root {
  --bg: #14120f;
  --fg: #f2ece3;
  --muted: #9b948a;
  --paper: #f6f1e7;
  --flip-ms: 700ms;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: Georgia, "Times New Roman", serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#masthead { text-align: center; }
#title {
  margin: 0;
  font-weight: 400;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  letter-spacing: .06em;
}
#subtitle {
  margin: .35rem 0 0;
  color: var(--muted);
  font-size: .9rem;
  font-style: italic;
}
#subtitle a {
  color: inherit;
  text-decoration-color: rgba(155, 148, 138, .5);
  text-underline-offset: .18em;
  transition: color .2s, text-decoration-color .2s;
}
#subtitle a:hover {
  color: var(--fg);
  text-decoration-color: currentColor;
}

/* ---------- book ---------- */

#stage {
  position: relative;
  touch-action: manipulation;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2400px;
}

#book {
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms) cubic-bezier(.3, .1, .2, 1);
  /* width/height/transform set by flip.js */
}

.leaf {
  position: absolute;
  top: 0;
  right: 0;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms) cubic-bezier(.3, .1, .2, 1);
}
.leaf.flipped { transform: rotateY(-180deg); }

/* flipped leaves in single-page mode swing off-stage, then hide */
#book.single .leaf { visibility: visible; transition: transform var(--flip-ms) cubic-bezier(.3,.1,.2,1), visibility 0s; }
#book.single .leaf.parked { visibility: hidden; transition: transform var(--flip-ms) cubic-bezier(.3,.1,.2,1), visibility 0s var(--flip-ms); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--bg);
}
.face.back { transform: rotateY(180deg); }

.face img {
  display: block;
  cursor: pointer;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg);
}

/* the gutter shadow near the spine */
.face::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9%;
  pointer-events: none;
}
.face.front::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, .28), transparent);
}
.face.back::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, .28), transparent);
}

/* single-page mode (phones) */
#book.single .leaf { width: 100%; }
#book.single .face.front::after,
#book.single .face.back::after { display: none; }

/* ---------- controls ---------- */

#controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
#controls button {
  background: none;
  border: 1px solid rgba(242, 236, 227, .3);
  color: var(--fg);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
  transition: border-color .2s, opacity .2s;
}
#controls button:hover:not(:disabled) { border-color: var(--fg); }
#controls button:disabled { opacity: .25; cursor: default; }

#counter {
  color: var(--muted);
  font-size: .9rem;
  min-width: 5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#hint {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  opacity: .75;
  text-align: center;
}

/* phones: give the page as much of the screen as possible */
@media (max-width: 700px) {
  body { gap: .85rem; padding: .9rem .75rem calc(.9rem + env(safe-area-inset-bottom)); }
  #title { font-size: 1.35rem; }
  #subtitle { font-size: .8rem; }
  #hint { display: none; }
  #controls { gap: 1.75rem; }
  #controls button { width: 2.75rem; height: 2.75rem; }
}

@media (max-height: 560px) {
  #masthead, #hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #book, .leaf { transition-duration: 1ms; }
}
