* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --room: #b48a60;
  --room-deep: #806247;
  --paper: #f4eedf;
  --ink: #39372f;
  --ink-soft: #7d796e;
  --olive: #858575;
  --room-gap: 84px;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background:
    linear-gradient(rgba(255, 236, 200, .06), rgba(64, 35, 14, .06)),
    var(--room) url("../assets/wood-table.webp") center / cover no-repeat;
  color: var(--ink);
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.reading-room {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  height: 100dvh;
  place-items: center;
  padding:
    calc(env(safe-area-inset-top, 0px) + 64px)
    calc(env(safe-area-inset-right, 0px) + 14px)
    calc(env(safe-area-inset-bottom, 0px) + 14px)
    calc(env(safe-area-inset-left, 0px) + 14px);
  isolation: isolate;
}

.room-light {
  position: absolute;
  inset: 8% 12%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 255, 246, .42), transparent 70%);
  filter: blur(22px);
  pointer-events: none;
}

.book-root {
  position: relative;
  z-index: 0;
  width: min(100%, 580px, calc((100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--room-gap)) * 430 / 590));
  height: auto;
  aspect-ratio: 430 / 590;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 580px;
  margin: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  filter: drop-shadow(0 19px 22px rgba(52, 48, 37, .24)) drop-shadow(0 3px 5px rgba(52, 48, 37, .18));
}

.book-root.stf__parent {
  width: min(100%, 580px, calc((100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--room-gap)) * 430 / 590)) !important;
  height: auto !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 580px !important;
  background: transparent;
  touch-action: none;
}

.book-root::before {
  position: absolute;
  z-index: -1;
  top: 0;
  bottom: 0;
  left: -5px;
  width: 10px;
  border-radius: 3px 0 0 3px;
  background: linear-gradient(90deg, rgba(68, 59, 42, .28), rgba(247, 240, 223, .7) 45%, rgba(90, 77, 57, .12));
  content: "";
  pointer-events: none;
}

.stf__wrapper,
.stf__block {
  overflow: visible;
}

.stf__block {
  perspective: 1800px;
}

.stf__item {
  transform-style: preserve-3d;
}

.book-page {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(131, 117, 88, .24);
  border-radius: 2px 4px 4px 2px;
  background: var(--paper) url("../assets/paper-texture.svg") repeat;
  background-size: 256px 256px;
  color: var(--ink);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.page-content {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: clamp(22px, 5.8%, 40px) clamp(20px, 7.4%, 48px) clamp(16px, 4%, 28px);
  background: linear-gradient(115deg, rgba(255, 255, 255, .18), transparent 30%, rgba(105, 87, 55, .025));
}

.book-page.page-back-pattern {
  background:
    url("../assets/page-back-pattern.svg") repeat,
    var(--paper) url("../assets/paper-texture.svg") repeat;
  background-size: 144px 144px, 256px 256px;
}

.page-back-pattern .page-content {
  visibility: hidden;
  pointer-events: none;
}

.page-back-illustrated .page-content {
  pointer-events: none;
}

.art-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 1.5% 2% 0;
}

.animal-art {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  cursor: pointer;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.animal-art[hidden] {
  display: none;
}

.animal-art:focus-visible {
  outline: 2px solid rgba(112, 119, 89, .68);
  outline-offset: -8px;
  border-radius: 10px;
}

.art-fallback {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: var(--ink-soft);
  font: clamp(48px, 15vw, 100px) Georgia, serif;
}

.art-fallback[hidden] {
  display: none;
}

.animal-name {
  margin: 1.5rem 0 0;
  color: #3c392f;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(1.55rem, 4.8vw, 2.5rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: .012em;
  text-align: center;
}

.page-footer {
  display: flex;
  justify-content: center;
  align-items: end;
  min-height: 2.6rem;
  padding-top: .75rem;
}

.page-number {
  margin: 0;
  color: #817c6f;
  font-size: .76rem;
  line-height: 1;
  letter-spacing: .11em;
  font-variant-numeric: oldstyle-nums;
}

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

@media (max-width: 600px) {
  :root {
    --room-gap: 84px;
  }

  .reading-room {
    padding:
      calc(env(safe-area-inset-top, 0px) + 64px)
      calc(env(safe-area-inset-right, 0px) + 10px)
      calc(env(safe-area-inset-bottom, 0px) + 10px)
      calc(env(safe-area-inset-left, 0px) + 10px);
  }

  .animal-name {
    margin-top: 1.1rem;
  }

  .page-footer {
    min-height: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

@media (max-height: 450px) {
  .animal-name {
    margin-top: .5rem;
    font-size: clamp(1.25rem, 7vh, 2rem);
  }

  .page-footer {
    min-height: 1.8rem;
  }
}


.language-picker {
  position: absolute;
  z-index: 10;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 14px);
  display: flex;
  gap: 2px;
  max-width: calc(100% - 28px);
  padding: 3px;
  border: 1px solid rgba(72, 44, 24, .22);
  border-radius: 24px;
  background: rgba(249, 239, 219, .94);
  box-shadow: 0 2px 8px rgba(60, 34, 16, .12);
}

.language-picker button,
.restart-book {
  min-height: 38px;
  border: 0;
  border-radius: 20px;
  padding: 0 14px;
  color: #514534;
  background: transparent;
  font: 14px Georgia, serif;
  cursor: pointer;
  touch-action: manipulation;
}

.language-picker button[aria-pressed="true"] {
  background: #66543e;
  color: #fff8e9;
}

.language-picker button:disabled { cursor: default; }
.language-picker button:focus-visible,
.restart-book:focus-visible {
  outline: 2px solid #776143;
  outline-offset: 2px;
}

.page-footer-last {
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.restart-book {
  min-height: 36px;
  padding: 0 16px;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
