/* Home intro. Paper curl. 1.2s closed cover, 1.8s cover opening, each
   page curl 2.2s ease-in-out, then a 1.05s fade. Faces use the site's
   self-hosted Instrument Serif and Cormorant SC. Leather, gold, and ox
   only. No purple. Namespaced so ledger-motion never sees .cover. */

.bbflip {
  --bbflip-cover: 1800ms;
  --bbflip-hold: 1200ms;
  --bbflip-turn: 2200ms;
  --bbflip-fade: 1050ms;
  --bbflip-paper: oklch(0.968 0.005 95);
  --bbflip-ink: oklch(0.23 0.01 60);
  --bbflip-ink2: oklch(0.42 0.014 60);
  --bbflip-gold: oklch(0.83 0.09 82);
  --bbflip-leather: oklch(0.19 0.012 50);
  --bbflip-leather-2: oklch(0.25 0.014 50);
  --bbflip-ox: oklch(0.47 0.13 32);
  --bbflip-ox-d: oklch(0.41 0.12 32);
  --bbflip-end: oklch(0.93 0.012 85);
  --bbflip-serif: "Instrument Serif", "Serif Fallback", Georgia, serif;
  --bbflip-label: "Cormorant SC", "Instrument Serif", Georgia, serif;
  --bw: min(780px, 42vw, calc(78vh * 220 / 300));
  --bh: calc(var(--bw) * 300 / 220);
  --paper: var(--bbflip-paper);
  --end: var(--bbflip-end);
  position: fixed;
  inset: 0;
  z-index: 40;
  /* Own layer so the curl does not repaint the page underneath. */
  contain: layout paint;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  /* iOS turns text autosizing back on inside a transformed layer and
     paints the glyphs at the top-left of that layer. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color: var(--bbflip-ink);
  background-color: #141210;
  background-image: radial-gradient(90% 60% at 70% 0%, var(--bbflip-leather-2), oklch(0.205 0.01 55) 70%);
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

.bbflip-behind {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--bw) * 2);
  height: var(--bh);
  transform: translate(-50%, -50%);
  background:
    linear-gradient(90deg, oklch(0.45 0.02 70 / .14), transparent 8%),
    var(--bbflip-paper);
  box-shadow: 0 34px 60px -24px #0009;
}

.bbflip-mask {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(90% 60% at 70% 0%, var(--bbflip-leather-2), oklch(0.205 0.01 55) 70%);
}

/* The fade is owned by the frame clock in book-flip.v2.js so it cannot
   finish before the cover and the curl, and so it stays on that clock. */

.bbflip.is-out {
  -webkit-animation: bbflip-fade 180ms linear forwards;
  animation: bbflip-fade 180ms linear forwards;
  pointer-events: none;
}

@-webkit-keyframes bbflip-fade {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes bbflip-fade {
  from { opacity: 1; }
  to { opacity: 0; }
}

.bbflip-scene {
  position: relative;
  width: calc(var(--bw) * 2);
  height: var(--bh);
  -webkit-perspective: 1600px;
  perspective: 1600px;
  perspective-origin: 50% 50%;
}

.bbflip-book {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--bw);
  height: var(--bh);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.bbflip-edges {
  position: absolute;
  z-index: 0;
  top: 2.3%;
  bottom: 2.3%;
  left: 3.6%;
  right: -4.5%;
  background: repeating-linear-gradient(90deg, var(--bbflip-paper) 0 2px, oklch(0.85 0.006 90) 2px 3px);
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 34px 60px -24px #0009;
}

.bbflip-sheet,
.bbflip-leaf,
.bbflip-face,
.bbflip-landed,
.bbflip-probe {
  position: absolute;
  inset: 0;
}

.bbflip-leaf-slot {
  position: absolute;
  inset: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.bbflip-leaf {
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  -webkit-transform-origin: left center;
  transform-origin: left center;
}

.bbflip-face {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.bbflip-front {
  -webkit-transform: rotateY(0deg) translateZ(0.6px);
  transform: rotateY(0deg) translateZ(0.6px);
  border-radius: 3px 8px 8px 3px;
}

.bbflip-back {
  -webkit-transform: rotateY(180deg) translateZ(0.6px);
  transform: rotateY(180deg) translateZ(0.6px);
  border-radius: 8px 3px 3px 8px;
}

.bbflip-sheet,
.bbflip-probe {
  background-color: var(--bbflip-paper);
  background-image: linear-gradient(90deg, oklch(0.45 0.02 70 / .14), transparent 16%);
  color: var(--bbflip-ink);
  box-shadow: inset 0 0 0 1px oklch(0.45 0.012 60 / .16);
  border-radius: 3px 8px 8px 3px;
}

.bbflip-sheet {
  z-index: 1;
  display: block;
  overflow: hidden;
  padding: 0;
  /* Same lengths as .bbflip-book. Not inset, and not a percentage height:
     iOS Safari drops both and the type sits on the top edge. */
  top: 0;
  right: auto;
  bottom: auto;
  left: 0;
  width: var(--bw);
  height: var(--bh);
  -webkit-transform-origin: left center;
  transform-origin: left center;
}

/* The sheet scales on X during the curl. This box is the same explicit
   size and only exists so the inverse scale can live on it. The type
   is vertically centered on .bbflip-copy, which the curl never writes
   a transform onto. The lines stay left-aligned, inset by the original
   11% of the page width. */
.bbflip-sheet-inner,
.bbflip-probe {
  padding: 0;
}

.bbflip-sheet-inner {
  position: absolute;
  top: 0;
  right: auto;
  bottom: auto;
  left: 0;
  width: var(--bw);
  height: var(--bh);
  margin: 0;
  display: block;
  -webkit-transform: none;
  transform: none;
  -webkit-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
}

.bbflip-copy {
  position: absolute;
  top: 50%;
  left: 0;
  width: var(--bw);
  box-sizing: border-box;
  margin: 0;
  /* Original page padding was 11% of the page width on each side. */
  padding: 0 calc(var(--bw) * 0.11);
  text-align: left;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}

.bbflip-kicker {
  display: block;
  width: auto;
  margin: 0 0 0.8em;
  padding: 0;
  font: 600 calc(var(--bw) * 0.0317 * 1.2) / 1.4 var(--bbflip-label);
  letter-spacing: 0.14em;
  text-transform: lowercase;
  text-align: left;
  color: var(--bbflip-ink2);
}

.bbflip-sheet p,
.bbflip-probe p,
.bbflip-copy p {
  display: block;
  width: auto;
  margin: 0;
  max-width: none;
  padding: 0;
  text-align: left;
  font: 400 calc(var(--bw) * 0.09) / 1.15 var(--bbflip-serif);
  color: var(--bbflip-ink);
}

.bbflip em {
  font-style: italic;
  color: var(--bbflip-ox);
}

.bbflip-landed {
  z-index: 2;
  right: auto;
  left: -100%;
  width: 100%;
  border-radius: 8px 3px 3px 8px;
  background:
    linear-gradient(270deg, oklch(0.45 0.02 70 / .16), transparent 18%),
    var(--bbflip-paper);
  box-shadow: inset 0 0 0 1px oklch(0.45 0.012 60 / .16);
  opacity: 0;
}

.bbflip-landed.on {
  opacity: 1;
  z-index: 7;
  -webkit-transform: translateZ(6px);
  transform: translateZ(6px);
}

.bbflip-probe {
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  top: 0;
  right: auto;
  bottom: auto;
  left: 0;
  width: var(--bw);
  height: var(--bh);
  display: block;
  text-align: center;
}

.bbflip-shadow,
.bbflip-curl {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  width: 200%;
  height: 100%;
  pointer-events: none;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.bbflip-cover { z-index: 6; }

.bbflip-board {
  background: radial-gradient(120% 90% at 30% 20%, var(--bbflip-leather-2), var(--bbflip-leather));
  box-shadow: inset 0 0 0 1px oklch(1 0 0 / .05);
  border-radius: 3px 8px 8px 3px;
  box-sizing: border-box;
  top: 0;
  right: auto;
  bottom: auto;
  left: 0;
  width: var(--bw);
  height: var(--bh);
  /* Right padding keeps the title clear of the ribbon. */
  padding: calc(var(--bw) * 0.06) calc(var(--bw) * 0.16) calc(var(--bw) * 0.06) calc(var(--bw) * 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.bbflip-frame {
  position: absolute;
  z-index: 0;
  inset: 5.5%;
  border: 1px solid oklch(0.83 0.09 82 / .2);
  border-radius: 3px;
}

.bbflip-board b {
  position: relative;
  z-index: 1;
  display: block;
  max-width: 100%;
  padding: 0;
  text-align: center;
  font: 400 calc(var(--bw) * 0.093) / 1.05 var(--bbflip-serif);
  color: oklch(0.8 0.07 80);
}

.bbflip-board i {
  position: relative;
  z-index: 1;
  margin-top: 0.55em;
  font: 600 calc(var(--bw) * 0.034 * 1.2) / 1 var(--bbflip-label);
  font-style: normal;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: oklch(0.7 0.06 80);
}

.bbflip-band {
  position: absolute;
  z-index: 2;
  top: calc(var(--bh) * -0.02);
  right: calc(var(--bw) * 0.045);
  width: calc(var(--bw) * 0.07);
  height: calc(var(--bh) * 1.14);
  background: linear-gradient(90deg, var(--bbflip-ox-d), var(--bbflip-ox));
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 96.5%, 0 100%);
}

.bbflip-endpaper {
  background:
    linear-gradient(90deg, oklch(0.55 0.02 70 / .18), transparent 14%),
    var(--bbflip-end);
  border-radius: 8px 3px 3px 8px;
}

.bbflip-endpaper.flat {
  background:
    linear-gradient(270deg, oklch(0.55 0.02 70 / .18), transparent 14%),
    var(--bbflip-end);
}

.bbflip-edge {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(90deg, #6b5344, #e6d9c4 45%, #f6f1e6);
  box-shadow: 0 0 0 1px oklch(0.32 0.02 55 / .45);
}

.bbflip.is-still .bbflip-leaf {
  -webkit-animation: none !important;
  animation: none !important;
}

.bbflip .bb-reveal-wait {
  position: absolute;
  z-index: 8;
  left: 0;
  right: 0;
  bottom: 9vh;
  text-align: center;
  pointer-events: auto;
}

@media (max-width: 720px) {
  .bbflip { --bw: min(168px, 42vw, calc(46vh * 220 / 300)); }
}

@media (prefers-reduced-motion: reduce) {
  .bbflip { display: none !important; }
}

@media print {
  .bbflip { display: none !important; }
}
