@font-face {
  font-family: Nunito;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/nunito-latin-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: Nunito;
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/nunito-latin-800-normal.woff2") format("woff2");
}

:root {
  --ink: #3a2418;
  --ink-soft: rgba(58, 36, 24, 0.4);
  --paper: #fff8ec;
  --paper-edge: #f1e0c4;
  --amber: #ffc857;
  --amber-deep: #f2a93b;
  --night: #2a2140;
  --wood: #8a5a34;
  --wood-dark: #5e3b20;
  --wall: #f6e7cf;
  --wall-dark: #ecd6b4;
  font-family: Nunito, ui-rounded, "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 600;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--night);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#app {
  min-height: 100%;
}

/* ---------- The shelf ---------- */

#app.shelf {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) 16px 48px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 214, 140, 0.55), transparent 55%),
    repeating-linear-gradient(90deg, var(--wall) 0 46px, var(--wall-dark) 46px 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.room-top {
  width: min(1100px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.pill {
  color: var(--ink);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.7);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 800;
}

.langs {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.7);
  padding: 4px;
  border-radius: 999px;
}

.langs button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
}

.langs button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.shelf h1 {
  font-weight: 800;
  font-size: clamp(34px, 6vw, 64px);
  margin: 28px 0 4px;
  letter-spacing: -0.01em;
  text-align: center;
}

.shelf .hint {
  margin: 0 0 28px;
  font-size: 20px;
  opacity: 0.8;
}

.books {
  position: relative;
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
  gap: 28px;
  padding-bottom: 34px;
}

.board {
  position: absolute;
  left: -12px;
  right: -12px;
  bottom: 0;
  height: 34px;
  border-radius: 6px;
  background: linear-gradient(var(--wood), var(--wood-dark));
  box-shadow: 0 14px 24px rgba(60, 30, 10, 0.3);
}

.book {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 0;
  padding: 0;
  border-radius: 10px 18px 18px 10px;
  overflow: hidden;
  background: var(--paper);
  border-left: 16px solid var(--spine);
  box-shadow:
    0 2px 0 var(--paper-edge),
    0 18px 30px rgba(60, 30, 10, 0.28);
  transition: transform 0.2s ease;
}

.book:hover,
.book:focus-visible {
  transform: translateY(-6px) rotate(-0.6deg);
}

.cover {
  display: block;
  aspect-ratio: 12 / 7;
  background: var(--night);
}

.cover svg {
  display: block;
  width: 100%;
  height: 100%;
}

.book-text {
  display: grid;
  gap: 6px;
  padding: 16px 18px 18px;
}

.book-text strong {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
}

.book-text em {
  font-style: normal;
  opacity: 0.8;
  font-size: 17px;
}

.book-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.age {
  font-size: 15px;
  background: var(--wall);
  padding: 4px 10px;
  border-radius: 999px;
}

.read {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--amber);
  padding: 10px 14px 10px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 18px;
}

.read svg {
  width: 20px;
  height: 20px;
}

/* ---------- The reader ---------- */

#app.reader {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--night);
  user-select: none;
  -webkit-user-select: none;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.page {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateX(4%) scale(1.02);
  transition:
    opacity 0.6s ease,
    transform 0.8s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.page.from-left {
  transform: translateX(-4%) scale(1.02);
}

.page.in {
  opacity: 1;
  transform: none;
}

.page.out {
  opacity: 0;
}

.page svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* The words */

/*
 * Over the picture (the screen is as wide as the painting, or wider): a slim,
 * see-through caption with only the line being read. Below the picture (there is
 * room under it): all the lines of the page on paper, nothing covers the picture.
 */
.band {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100vw - 220px), 1080px);
  padding: 10px 22px 12px;
  border-radius: 22px;
  background: rgba(255, 248, 236, 0.66);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  box-shadow: 0 8px 28px rgba(20, 12, 30, 0.22);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 32vh;
  transition:
    opacity 0.5s ease,
    transform 0.5s ease;
}

/* The painting says where its words go over it: at the top (mostly sky) or the bottom. */
#app.reader:not(.below)[data-caption="top"] .band {
  top: max(14px, env(safe-area-inset-top));
  bottom: auto;
  width: min(calc(100vw - 260px), 980px);
}

/* When the page is read, the words step aside and only the picture is left. */
#app.reader.read-done:not(.below) .band {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
}

#app.reader.read-done:not(.below)[data-caption="top"] .band {
  transform: translate(-50%, -10px);
}

.text {
  overflow-y: auto;
  font-size: clamp(18px, 2vw, 30px);
  line-height: 1.4;
  cursor: pointer;
  scrollbar-width: none;
}

/* Over the picture only the current line shows. */
#app.reader:not(.below) .line:not(.last) {
  display: none;
}

#app.reader:not(.below) .line {
  margin: 0;
}

#app.reader:not(.below) .w {
  color: rgba(58, 36, 24, 0.55);
}

.line {
  margin: 0 0 0.35em;
  transition: opacity 0.3s ease;
}

.line.speech {
  padding-left: 0.6em;
  border-left: 5px solid var(--who);
}

.who {
  display: inline-block;
  font-size: 0.62em;
  font-weight: 800;
  color: var(--paper);
  background: var(--who);
  padding: 0.05em 0.6em;
  border-radius: 999px;
  margin-right: 0.45em;
  vertical-align: 0.25em;
}

.w {
  color: var(--ink-soft);
  border-radius: 0.3em;
  padding: 0 0.06em;
  transition:
    color 0.15s ease,
    background-color 0.15s ease;
}

.w.said,
.line.done .w {
  color: var(--ink);
}

.line.speech .w.said {
  color: var(--who);
}

.w.now {
  color: var(--ink);
  background: var(--amber);
  box-shadow: 0 0 0 0.12em var(--amber);
}

.title-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle, rgba(42, 33, 64, 0.55), rgba(42, 33, 64, 0.85));
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.title-card.in {
  opacity: 1;
}

.title-card h1 {
  margin: 0;
  max-width: 14em;
  text-align: center;
  color: var(--paper);
  font-weight: 800;
  font-size: clamp(36px, 6vw, 80px);
  line-height: 1.1;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Ways on: small buttons floating at the bottom, over the picture or the paper */

.ways {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 200px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.ways:empty {
  display: none;
}

.ways > p,
.dots {
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 248, 236, 0.86);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(20, 12, 30, 0.18);
}

.choose {
  font-size: 15px;
}

#app.reader:not(.below) .choose {
  display: none;
}

.way {
  border: 2px solid var(--amber-deep);
  background: rgba(255, 248, 236, 0.88);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-weight: 800;
  font-size: clamp(15px, 1.5vw, 19px);
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(20, 12, 30, 0.2);
  transition:
    transform 0.15s ease,
    background-color 0.2s ease;
}

.way.quiet {
  border-color: var(--paper-edge);
}

.way:active {
  transform: translateY(2px);
}

.way.glow {
  background: var(--amber);
  transform: scale(1.06);
}

.the-end {
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 800;
}

.dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--paper-edge);
  transition: background-color 0.2s ease;
}

.dot.on {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
}

/* Buttons */

.bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none;
}

.top-bar {
  top: 0;
}

.spacer {
  flex: 1;
}

.round {
  pointer-events: auto;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 248, 236, 0.85);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.round svg {
  width: 26px;
  height: 26px;
}

.round:disabled {
  opacity: 0.35;
  cursor: default;
}

.round.big {
  width: 76px;
  height: 76px;
  background: var(--amber);
  box-shadow: 0 5px 0 var(--amber-deep);
}

.round.big svg {
  width: 38px;
  height: 38px;
}

.next {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  animation: nudge 1.6s ease-in-out infinite;
}

.next[hidden] {
  display: none;
}

/* Room below the picture (portrait, tablets): the whole picture on top, the words below it. */

#app.reader.below .stage {
  bottom: auto;
  height: var(--pic-h, 56vh);
}

#app.reader.below .band {
  top: var(--pic-h, 56vh);
  bottom: 0;
  left: 0;
  width: auto;
  right: 0;
  transform: none;
  max-height: none;
  border-radius: 0;
  padding: 18px max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--paper);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 -6px 20px rgba(20, 12, 30, 0.18);
}

#app.reader.below .text {
  padding-right: 96px;
  font-size: clamp(20px, 3.6vw, 32px);
}

#app.reader.below .band {
  padding-bottom: 72px;
}

/* ---------- Things in the pictures ---------- */

.picture .hot,
.picture [data-tap] {
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
}

.picture .hot:not(.spot) {
  animation: breathe 2.4s ease-in-out infinite;
}

.picture .hot.glow:not(.spot) {
  animation: bounce 0.6s ease-in-out infinite;
}

.picture .hot.picked:not(.spot) {
  animation: none;
  transform: scale(1.12);
  transition: transform 0.3s ease;
}

.picture .tap:not(.spot) {
  animation: bob 1.8s ease-in-out infinite;
}

.picture .tap:not(.spot):nth-child(odd) {
  animation-delay: 0.4s;
}

/*
 * Spots on the paintings: only a soft light, breathing gently from the start and
 * a little brighter once the page is read. The way being said aloud glows fully.
 */
.spot {
  cursor: pointer;
}

.spot .spot-glow {
  opacity: 0;
  mix-blend-mode: screen;
  transition: opacity 0.4s ease;
}

.spot.hot .spot-glow,
.spot.tap .spot-glow {
  animation: spot-breathe 3s ease-in-out infinite;
}

.spot.offer .spot-glow {
  animation: spot-offer 1.8s ease-in-out infinite;
}

.spot.glow .spot-glow,
.spot.picked .spot-glow {
  opacity: 1;
  animation: none;
}

/* A stone carried home lights up where it lies. */
.spot.tap.gone .spot-glow {
  opacity: 1;
  animation: spot-lit 0.9s ease-out;
}

@keyframes spot-breathe {
  0%,
  100% {
    opacity: 0.2;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes spot-offer {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 0.9;
  }
}

@keyframes spot-lit {
  from {
    opacity: 0.2;
  }
  60% {
    opacity: 1;
  }
}

.picture .tap:not(.spot).gone {
  animation: none;
  opacity: 0;
  transform: translateY(-140px) scale(0.3);
  transition:
    transform 0.7s cubic-bezier(0.3, 0.6, 0.3, 1),
    opacity 0.7s ease;
}

.picture .pulse {
  animation: pulse 3s ease-in-out infinite;
}

.page.solved .picture .pulse {
  animation-duration: 1.2s;
}

.picture .twinkle {
  animation: twinkle 4s ease-in-out infinite;
}

.picture .rise {
  animation: rise 5s linear infinite;
}

.picture .sway {
  transform-box: fill-box;
  transform-origin: center;
  animation: sway 5s ease-in-out infinite;
}

@keyframes breathe {
  50% {
    transform: scale(1.04);
  }
}

@keyframes bounce {
  50% {
    transform: scale(1.1) translateY(-2%);
  }
}

@keyframes bob {
  50% {
    transform: translateY(-8%);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

@keyframes twinkle {
  50% {
    opacity: 0.2;
  }
}

@keyframes rise {
  from {
    transform: translateY(0);
    opacity: 0.9;
  }
  to {
    transform: translateY(-160px);
    opacity: 0;
  }
}

@keyframes sway {
  50% {
    transform: translateX(24px) scale(1.06);
  }
}

@keyframes nudge {
  50% {
    transform: translateX(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
