/*
 * How to play, the booklet (js/screens/guide.js). Every part has a fixed
 * place and size: the scene, the words under it, and Back, the dots and Next
 * along the bottom. Nothing scrolls and nothing moves as pages turn.
 */
.booklet {
  width: min(94vw, 46rem);
  height: min(88dvh, 37rem);
  max-height: none;
  padding: var(--space-4) var(--space-5);
  overflow: hidden;
}

.booklet[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--space-3);
}

.booklet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.booklet__page {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--space-4);
  min-height: 0;
  /* Swipes turn pages: the browser must not take them for itself. */
  touch-action: none;
  user-select: none;
}

.booklet__stage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-0);
  overflow: hidden;
}

.booklet__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.booklet__keyslot {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
}

.booklet__keys {
  display: grid;
  gap: var(--space-2);
}

.booklet__key {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.booklet__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  justify-content: flex-end;
}

.booklet kbd {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.2;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--text);
  white-space: nowrap;
}

/* Fixed height, sized for the longest page (guide-pages.js MAX_TEXT). */
.booklet__text {
  height: 7.5rem;
  overflow: hidden;
}

.booklet__title {
  font-size: var(--text-lg);
  margin: 0 0 var(--space-1);
}

.booklet__words {
  margin: 0;
  max-width: 62ch;
}

.booklet__nav {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr) 7rem;
  align-items: center;
  gap: var(--space-3);
}

.booklet__back,
.booklet__next {
  width: 100%;
  min-height: var(--target);
}

.booklet__dots {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
}

.booklet__dot {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background-color var(--dur-quick) var(--ease-standard);
}

.booklet__dot.is-on {
  background: var(--accent);
}

/* A page arrives as a soft fade in place: no slide, nothing travels. */
.booklet__page.is-turning > * {
  animation: booklet-in var(--dur-base) var(--ease-enter) both;
}

@keyframes booklet-in {
  from {
    opacity: 0.25;
  }
}

/* A short window: the controls close up, and below 560px the words move
   beside the scene, as on a phone held sideways. */
@media (max-height: 640px) {
  .booklet__keys {
    gap: var(--space-1);
  }
}

@media (max-height: 560px) {
  .booklet {
    height: 94dvh;
    padding: var(--space-3) var(--space-4);
  }

  .booklet[open] {
    gap: var(--space-2);
  }

  .booklet__page {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: var(--space-3);
  }

  .booklet__text {
    height: auto;
  }

  .booklet__title {
    font-size: var(--text-md);
  }

  .booklet__words {
    font-size: var(--text-sm);
  }

  .booklet__key {
    grid-template-columns: 8rem minmax(0, 1fr);
    font-size: var(--text-xs);
  }
}

/* A very small window: smaller words, so every page still fits. */
@media (max-height: 420px) {
  .booklet__words {
    font-size: var(--text-xs);
  }

  .booklet__keys {
    gap: 0;
  }

  .booklet__keyslot {
    padding: var(--space-1) var(--space-2);
  }

  .booklet__key {
    grid-template-columns: 6.5rem minmax(0, 1fr);
    gap: var(--space-2);
    line-height: 1.25;
  }
}

/* ---- A phone: the whole screen, scene above, words below ---- */
:root[data-phone='true'] .booklet {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: max(var(--space-2), env(safe-area-inset-top))
    max(var(--space-4), env(safe-area-inset-right)) max(var(--space-3), env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
}

:root[data-phone='true'] .booklet__page {
  gap: var(--space-3);
  align-content: start;
}

/* Upright, the scene keeps a landscape-ish frame; the spare height falls
   between the words and the buttons, which stay at the bottom. */
:root[data-phone='true'][data-orient='portrait'] .booklet__page {
  grid-template-rows: minmax(0, 22rem) auto;
}

:root[data-phone='true'][data-orient='portrait'] .booklet__stage {
  height: 100%;
}

:root[data-phone='true'] .booklet__text {
  height: 10.5rem;
}

:root[data-phone='true'] .booklet__words {
  font-size: var(--text-sm);
}

:root[data-phone='true'] .booklet__key {
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: var(--space-2);
  line-height: 1.3;
}

:root[data-phone='true'] .booklet__keyslot {
  padding: var(--space-2) var(--space-3);
}

:root[data-phone='true'] .booklet__nav {
  grid-template-columns: 5.5rem minmax(0, 1fr) 5.5rem;
  gap: var(--space-2);
}

/* Sideways: the scene on the left, the words on the right. */
:root[data-phone='true'][data-orient='landscape'] .booklet[open] {
  gap: var(--space-2);
}

:root[data-phone='true'][data-orient='landscape'] .booklet__page {
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

:root[data-phone='true'][data-orient='landscape'] .booklet__text {
  height: auto;
}

:root[data-phone='true'][data-orient='landscape'] .booklet__title {
  font-size: var(--text-md);
}

:root[data-phone='true'][data-orient='landscape'] .booklet__keys {
  gap: 0.2rem;
}

:root[data-phone='true'][data-orient='landscape'] .booklet__key {
  grid-template-columns: 8rem minmax(0, 1fr);
  font-size: var(--text-xs);
}
