/* ==========================================================================
   Sightseeing Sophie — the digital book reader (/read/{slug}) and the bookshelf (/library).
   Loaded on those pages only, after main.css (its tokens, buttons, bubbles and stamps).
   ========================================================================== */

/* The reader fills the screen like an app: nothing scrolls behind it. */
html:has(.page-reader), .page-reader { overflow: hidden; height: 100%; overscroll-behavior: none; }
.reader {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background:
    radial-gradient(70% 60% at 50% 42%, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, var(--sky) 0%, color-mix(in srgb, var(--tint) 55%, #fff) 62%, var(--tint) 100%);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.reader__sky { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.reader__sky .cloud { position: absolute; height: auto; opacity: 0.95; filter: drop-shadow(0 10px 18px rgba(29, 54, 64, 0.06)); }
.cloud--r1 { width: clamp(120px, 16vw, 260px); aspect-ratio: 2; top: 9%; left: -4%; animation: r-drift 90s linear infinite; }
.cloud--r2 { width: clamp(90px, 11vw, 190px); aspect-ratio: 2; top: 22%; right: 3%; animation: r-drift 120s linear infinite reverse; }
.cloud--r3 { width: clamp(80px, 9vw, 150px); aspect-ratio: 2; bottom: 12%; left: 8%; animation: r-drift 140s linear infinite; }
@keyframes r-drift { 0%, 100% { translate: 0 0; } 50% { translate: 6vw 1vh; } }

/* Top bar ------------------------------------------------------------------ */
.reader__bar {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 6px max(14px, env(safe-area-inset-left));
}
.reader__where { font-family: var(--font-display); font-variation-settings: 'SOFT' 100; font-size: clamp(0.95rem, 1.4vw, 1.15rem); font-weight: 600; color: var(--ink); text-align: center; white-space: nowrap; }
.reader__tools { display: flex; justify-content: flex-end; gap: 8px; }
.rtool {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: background 0.3s, color 0.3s, transform 0.3s var(--ease-spring);
}
.rtool:hover { background: #fff; transform: translateY(-1px); }
.rtool:active { transform: scale(0.96); }
.rtool--back { justify-self: start; max-width: 100%; }
.rtool--back .rtool__label { overflow: hidden; text-overflow: ellipsis; }
.rtool--icon { width: 44px; padding: 0; justify-content: center; }
.rtool .icon { width: 20px; height: 20px; }
.rtool[data-reader-words][aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.rtool--read { background: var(--coral-deep); color: #fff; }
.rtool--read:hover { background: var(--coral); }
.rtool--read[aria-pressed='true'] { background: var(--ink); }

/* Classic | Immersive, the book's two versions (preview builds): shown on the cover, so you choose
   one as you open the book. This reader is the Classic one. On wide screens it takes the "Cover"
   label's place in the bar; on narrower ones (where the bar is full) it sits low, under the book. */
.vswitch { display: inline-flex; gap: 3px; padding: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.82); box-shadow: var(--shadow-sm); backdrop-filter: blur(8px); }
.vswitch__opt { display: inline-flex; align-items: center; gap: 0.45em; height: 36px; padding: 0 14px; border-radius: 999px; color: var(--ink); font-weight: 700; font-size: 0.92rem; white-space: nowrap; text-decoration: none; transition: background 0.3s, color 0.3s; }
.vswitch__opt .icon { width: 18px; height: 18px; }
.vswitch__opt:hover { background: #fff; }
.vswitch__opt[aria-current='page'] { background: var(--ink); color: var(--paper); }
.reader__versions { display: none; grid-column: 2; grid-row: 1; justify-self: center; }
.reader.is-cover .reader__versions { display: inline-flex; }
.reader.is-cover:has(.reader__versions) .reader__where { display: none; }
@media (min-width: 940px) {
  .reader.is-cover:has(.reader__versions) .reader__bar { grid-template-columns: auto minmax(0, 1fr) auto; }
}
/* room to spare: right in the middle, over the closed book */
@media (min-width: 1240px) {
  .reader__versions { position: absolute; grid-area: auto; left: 50%; top: max(10px, env(safe-area-inset-top)); translate: -50% 0; }
}
/* width: max-content, because a box placed at left: 50% only gets the other half of the screen to
   fit in, and Safari squeezed the switch into it, cutting off "Classic" and "Immersive" on iPhones
   (the user, 2026-11-28: "This is gettin slightly cut off"). */
@media (max-width: 939px) {
  .reader__versions { position: fixed; left: 50%; bottom: 12px; z-index: 4; width: max-content; translate: -50% 0; }
}

/* The stage and the book ------------------------------------------------------ */
.reader__stage {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 6px clamp(64px, 7vw, 110px) 14px;
  container-type: size;
  touch-action: pan-y pinch-zoom;
}
/* A page's width ÷ height (book.json, set by reader.js; 612 × 792 until then), and the cover's
   (read.mjs, from the cover picture). */
.reader { --page-ar: 0.7727; --cover-ar: 0.737; }
.rbook {
  --ar: calc(var(--page-ar) * 2); /* two pages side by side */
  --stack-l: 0px;
  --stack-r: 7px;
  position: relative;
  width: min(100cqw, 100cqh * var(--ar));
  aspect-ratio: var(--ar);
  transition: transform 0.8s var(--ease);
}
.rbook.is-single { --ar: var(--page-ar); }
/* The closed book: the cover sits on the right half of the box, so slide it to the middle. */
.rbook.is-closed { transform: translateX(-25%); }
.rbook__loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; font-weight: 600; color: var(--ink-2); }
.rbook__plane { width: 40px; height: 40px; color: var(--coral); animation: r-fly 1.6s var(--ease-in-out) infinite; }
@keyframes r-fly { 0%, 100% { translate: -14px 4px; } 50% { translate: 14px -4px; } }

.rsheet { position: absolute; inset: 0; display: flex; }
.rpage {
  position: relative;
  flex: 1 1 50%;
  min-width: 0;
  background: #fffdf8;
  overflow: hidden;
  container-type: size;
  box-shadow: 0 2px 6px rgba(29, 54, 64, 0.08), 0 24px 50px -22px rgba(29, 54, 64, 0.45);
}
.rsheet--single .rpage { flex-basis: 100%; border-radius: 6px 12px 12px 6px; }
.rsheet--spread .rpage--left, .rsheet--wide .rpage--left { border-radius: 12px 2px 2px 12px; }
.rsheet--spread .rpage--right, .rsheet--wide .rpage--right { border-radius: 2px 12px 12px 2px; }
.rpage--empty, .rpage--hole { background: none; box-shadow: none; }
.rpage.is-loading { background: linear-gradient(110deg, #fffdf8 30%, color-mix(in srgb, var(--tint) 45%, #fff) 50%, #fffdf8 70%) 0 0 / 300% 100%; animation: r-shimmer 1.4s linear infinite; }
@keyframes r-shimmer { to { background-position: -150% 0; } }
.rpage__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.rpage.is-loading .rpage__img { opacity: 0; }
.rpage__img { transition: opacity 0.25s; }

/* The spine: shading into the fold, and the stacked page edges at the outer sides. */
.rsheet--spread .rpage--left::after, .rsheet--wide .rpage--left::after,
.rsheet--spread .rpage--right::after, .rsheet--wide .rpage--right::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9%;
  pointer-events: none;
}
.rsheet--spread .rpage--left::after, .rsheet--wide .rpage--left::after { right: 0; background: linear-gradient(to left, rgba(40, 30, 20, 0.2), rgba(40, 30, 20, 0.05) 45%, rgba(40, 30, 20, 0)); }
.rsheet--spread .rpage--right::after, .rsheet--wide .rpage--right::after { left: 0; background: linear-gradient(to right, rgba(40, 30, 20, 0.16), rgba(40, 30, 20, 0.04) 45%, rgba(40, 30, 20, 0)); }
.rsheet--spread .rpage--left:not(.rpage--empty):not(.rpage--hole) { box-shadow: calc(var(--stack-l) * -1) 0 0 -1px #f3ece0, 0 2px 6px rgba(29, 54, 64, 0.08), 0 24px 50px -22px rgba(29, 54, 64, 0.45); }
.rsheet--spread .rpage--right:not(.rpage--empty):not(.rpage--hole) { box-shadow: var(--stack-r) 0 0 -1px #f3ece0, 0 2px 6px rgba(29, 54, 64, 0.08), 0 24px 50px -22px rgba(29, 54, 64, 0.45); }

/* A page being turned: two faces back to back, folding over the spine. */
.rleaf { --p: 0; position: absolute; top: 0; bottom: 0; z-index: 3; transform-style: preserve-3d; will-change: transform; }
.rleaf--fwd { left: 50%; width: 50%; transform-origin: 0 50%; }
.rleaf--back { left: 0; width: 50%; transform-origin: 100% 50%; }
.rleaf--single { left: 0; width: 100%; transform-origin: 0 50%; }
.rbook { perspective: calc(100cqw * 2.2); }
.rleaf__face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.rleaf__face--back { transform: rotateY(180deg); }
.rleaf__face > .rpage { position: absolute; inset: 0; }
/* Light and shade as the page lifts: darkest when it stands up straight. */
.rleaf__face::after { content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit; }
.rleaf--fwd .rleaf__face--front::after, .rleaf--single .rleaf__face--front::after { background: linear-gradient(to right, rgba(29, 20, 10, 0.32), rgba(29, 20, 10, 0.04) 60%, rgba(255, 255, 255, 0.08)); opacity: calc(var(--p) * 1.6); }
.rleaf--fwd .rleaf__face--back::after, .rleaf--single .rleaf__face--back::after { background: linear-gradient(to left, rgba(29, 20, 10, 0.3), rgba(29, 20, 10, 0.03) 60%); opacity: calc((1 - var(--p)) * 1.6); }
.rleaf--back .rleaf__face--front::after { background: linear-gradient(to left, rgba(29, 20, 10, 0.32), rgba(29, 20, 10, 0.04) 60%); opacity: calc(var(--p) * 1.6); }
.rleaf--back .rleaf__face--back::after { background: linear-gradient(to right, rgba(29, 20, 10, 0.3), rgba(29, 20, 10, 0.03) 60%); opacity: calc((1 - var(--p)) * 1.6); }
.rpage--paper { background: linear-gradient(to left, #f6efe3, #fffdf8 40%); }

/* The words: invisible boxes over the printed words that light up like a highlighter. */
.rpage__words { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.rword { fill: #ffd84d; opacity: 0; mix-blend-mode: multiply; pointer-events: auto; cursor: pointer; transition: opacity 0.18s; }
.rword.is-on { opacity: 0.72; }
.rword.is-tap { animation: r-tap 0.9s var(--ease); }
@keyframes r-tap { 0% { opacity: 0; } 18% { opacity: 0.78; } 100% { opacity: 0; } }

/* Fun-fact stars and their bubbles. */
.rfact {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: clamp(30px, 8.5cqw, 54px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--butter);
  color: var(--coral-deep);
  box-shadow: 0 0 0 3px #fff, 0 8px 18px -6px rgba(29, 54, 64, 0.55);
  translate: -50% -50%;
  animation: r-twinkle 2.6s var(--ease-in-out) infinite;
}
.rfact .icon { width: 58%; height: 58%; }
.rfact.is-seen { animation: none; background: #fff; color: var(--ink-3); }
@keyframes r-twinkle { 0%, 100% { scale: 1; rotate: 0deg; } 50% { scale: 1.14; rotate: 14deg; } }
.rfact__bubble {
  position: absolute;
  z-index: 3;
  width: min(78cqw, 300px);
  padding: 0.9em 1.1em;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: clamp(0.85rem, 4.2cqw, 1.05rem);
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  translate: -50% 0;
  animation: r-pop 0.45s var(--ease-spring) both;
}
.rfact__bubble.is-below { margin-top: clamp(22px, 6cqw, 36px); }
.rfact__bubble.is-above { translate: -50% calc(-100% - clamp(22px, 6cqw, 36px)); }
@keyframes r-pop { from { opacity: 0; scale: 0.6; } }

/* Turn buttons at the sides; on phones they sit low, out of the picture. */
.rnav {
  position: absolute;
  top: 50%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  translate: 0 -50%;
  transition: transform 0.35s var(--ease-spring), opacity 0.3s;
}
.rnav:hover { transform: scale(1.08); }
.rnav:active { transform: scale(0.94); }
.rnav:disabled { opacity: 0; pointer-events: none; }
.rnav .icon { width: 24px; height: 24px; }
.rnav--prev { left: max(10px, env(safe-area-inset-left)); }
.rnav--next { right: max(10px, env(safe-area-inset-right)); background: var(--coral-deep); color: #fff; }
.reader.is-cover .rnav--next { animation: r-nudge 1.8s var(--ease-in-out) infinite; }
@keyframes r-nudge { 0%, 100% { translate: 0 -50%; } 50% { translate: 6px -50%; } }

/* Big Words: the words on screen, large, under the book. */
.reader__caption {
  position: relative;
  z-index: 3;
  max-height: 32svh;
  margin: 0 max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  padding: 14px clamp(16px, 3vw, 28px);
  border-radius: 22px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  overflow: auto;
  overscroll-behavior: contain;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  font-weight: 500;
  line-height: 1.55;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.reader__caption p + p { margin-top: 0.6em; }
.rcap__w { border-radius: 6px; transition: background 0.18s; }
.rcap__w.is-on { background: #ffe680; box-shadow: 0 0 0 2px #ffe680; }

.reader__progress { position: relative; z-index: 3; height: 5px; margin: 0 max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); border-radius: 99px; background: rgba(29, 54, 64, 0.1); overflow: hidden; }
.reader__progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--tone); transition: width 0.6s var(--ease); }
/* width: max-content, as for the version switch: placed at left: 50%, it otherwise only gets half the
   screen and its messages wrap into a narrow column on phones (audit, 2026-11-28). */
.reader__toast { position: absolute; left: 50%; bottom: 28px; z-index: 8; width: max-content; max-width: min(90vw, 520px); padding: 12px 20px; border-radius: 16px; background: var(--ink); color: var(--paper); font-weight: 600; box-shadow: var(--shadow); translate: -50% 0; animation: r-pop 0.4s var(--ease-spring); }
.reader__noscript { position: absolute; inset: 40% 10% auto; padding: 20px; border-radius: 20px; background: #fff; text-align: center; }

/* Cards: the cover, "to be continued", the end ------------------------------- */
.rface { position: absolute; inset: 0; }
/* A hardcover is usually a little taller than its pages (Rome's: 900 × 1221 against 612 × 792),
   so it overhangs them top and bottom, as a real one does. */
.rpage--card:has(.rface--cover) { overflow: visible; background: none; box-shadow: none; }
.rface--cover { inset: calc((var(--page-ar) / var(--cover-ar) - 1) * -50%) 0; }
.rface--cover img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px 14px 14px 4px; box-shadow: inset 6px 0 10px -6px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(29, 54, 64, 0.12), 0 30px 60px -24px rgba(29, 54, 64, 0.55); }
.rface--cover::before { content: ''; position: absolute; inset: 0 auto 0 0; z-index: 1; width: 4%; border-radius: 4px 0 0 4px; background: linear-gradient(to right, rgba(0, 0, 0, 0.18), rgba(255, 255, 255, 0.18) 45%, rgba(0, 0, 0, 0.06)); pointer-events: none; }
.rcover__open {
  position: absolute;
  left: 50%;
  bottom: 6%;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.75em 1.3em;
  border-radius: 999px;
  background: var(--coral-deep);
  color: #fff;
  font-weight: 700;
  font-size: clamp(0.8rem, 4.4cqw, 1.1rem);
  white-space: nowrap;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9), 0 14px 26px -10px rgba(140, 40, 30, 0.7);
  translate: -50% 0;
  animation: r-bounce 2.2s var(--ease-in-out) infinite;
}
.rcover__open .icon { width: 1.2em; height: 1.2em; }
@keyframes r-bounce { 0%, 100% { translate: -50% 0; } 50% { translate: -50% -8px; } }

.rface--teaser { display: grid; place-items: center; background: color-mix(in srgb, var(--tint) 50%, #fff); }
.rteaser { position: relative; width: 62cqw; aspect-ratio: var(--page-ar); }
.rteaser__page { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 6px; box-shadow: var(--shadow); }
.rteaser__page--1 { rotate: -7deg; translate: -14% 2%; }
.rteaser__page--2 { rotate: 5deg; translate: 12% -3%; }
.rteaser__page--3 { rotate: -1deg; }
.rteaser__badge { position: absolute; left: 50%; bottom: 8%; display: inline-flex; align-items: center; gap: 0.45em; padding: 0.6em 1.1em; border-radius: 999px; background: var(--ink); color: var(--paper); font-weight: 700; font-size: clamp(0.75rem, 4cqw, 1rem); white-space: nowrap; translate: -50% 0; }

.rface--pay {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 3cqh, 22px);
  padding: 9cqw;
  background:
    radial-gradient(circle at 1px 1px, rgba(29, 54, 64, 0.08) 1px, transparent 1.4px) 0 0 / 18px 18px,
    #fffdf8;
  -webkit-user-select: text;
  user-select: text;
}
.rface--pay .eyebrow { font-size: clamp(0.62rem, 3cqw, 0.8rem); }
.rpay__title { font-size: clamp(1.5rem, 11cqw, 3.4rem); line-height: 1; letter-spacing: -0.03em; }
.rpay__title em { color: var(--tone); }
.rpay__text { font-size: clamp(0.82rem, 4.2cqw, 1.12rem); line-height: 1.5; color: var(--ink-2); }
.rpay__price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3em 0.8em; }
.rpay__price strong { font-family: var(--font-display); font-size: clamp(1.4rem, 9cqw, 2.6rem); letter-spacing: -0.03em; }
.rpay__price span { font-size: clamp(0.78rem, 3.6cqw, 1rem); font-weight: 600; color: var(--tone-ink); }
.rpay__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.rface--pay .btn { height: clamp(42px, 13cqw, 58px); font-size: clamp(0.82rem, 3.8cqw, 1rem); }
.rface--pay .btn--sm { height: clamp(38px, 11cqw, 46px); }
.rpay__have { font-size: clamp(0.78rem, 3.6cqw, 0.95rem); color: var(--ink-2); }
.rpay__have a { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.rface--end { display: grid; justify-items: center; align-content: center; gap: 2cqh; padding: 7cqw; background: color-mix(in srgb, var(--tint) 45%, #fffdf8); text-align: center; }
.rend__the { font-family: var(--font-display); font-variation-settings: 'SOFT' 100; font-style: italic; font-size: clamp(1.8rem, 14cqw, 4.6rem); line-height: 1; color: var(--tone); }
.rend__sophie { position: relative; width: 34cqw; }
.rend__sophie img { width: 100%; height: auto; }
.rend__bubble { left: 74%; top: 2%; font-size: clamp(0.6rem, 2.8cqw, 1rem); }
.rend__bubble .bubble__word { font-size: 1.5em; }
.rend__bubble .bubble__lang { font-size: 1.1em; }
.rend__stamp { position: absolute; right: 6%; top: 5%; width: 22cqw; rotate: 10deg; }
.rend__stamp .stamp { width: 100%; }
.rend__note { font-weight: 700; font-size: clamp(0.85rem, 4.4cqw, 1.2rem); }

.rface--next { display: flex; flex-direction: column; justify-content: center; gap: 4cqh; padding: 8cqw; background: #fffdf8; }
.rface--next .eyebrow { font-size: clamp(0.62rem, 3cqw, 0.8rem); }
.rnext { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5cqw; }
.rnext a { display: grid; justify-items: center; gap: 0.5em; font-weight: 700; font-size: clamp(0.75rem, 3.6cqw, 1rem); transition: transform 0.4s var(--ease-spring); }
.rnext a:hover { transform: translateY(-4px) rotate(-2deg); }
.rnext img { border-radius: 2px 6px 6px 2px; box-shadow: var(--shadow); }
.rnext__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.rface--next .btn { height: clamp(40px, 12cqw, 46px); font-size: clamp(0.8rem, 3.6cqw, 0.93rem); }

/* The page grid ------------------------------------------------------------------ */
.rgrid { width: min(960px, calc(100vw - 24px)); max-height: calc(100svh - 24px); padding: 0; border: 0; border-radius: 28px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); }
.rgrid::backdrop { background: rgba(29, 54, 64, 0.45); backdrop-filter: blur(4px); }
.rgrid__panel { display: grid; grid-template-rows: auto minmax(0, 1fr); max-height: calc(100svh - 24px); }
.rgrid__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 10px; }
.rgrid__title { font-size: clamp(1.4rem, 3vw, 2rem); }
.rgrid__close { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); }
.rgrid__list { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px; padding: 8px 22px 24px; overflow: auto; overscroll-behavior: contain; }
.rgrid__item { position: relative; display: grid; gap: 6px; width: 100%; font-size: 0.82rem; font-weight: 600; color: var(--ink-2); text-align: center; }
.rgrid__item img { width: 100%; aspect-ratio: var(--page-ar); object-fit: cover; border-radius: 6px; background: #fff; box-shadow: var(--shadow-sm); transition: transform 0.35s var(--ease); }
.rgrid__item:hover img { transform: translateY(-3px); }
.rgrid__item.is-locked img { opacity: 0.75; }
.rgrid__lock { position: absolute; left: 50%; top: 38%; width: 34px; height: 34px; padding: 7px; border-radius: 50%; background: var(--ink); color: var(--paper); translate: -50% -50%; }

/* Phones: one page, compact bar, turn buttons low at the sides. */
@media (max-width: 700px) {
  .reader__bar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px; }
  .rtool { height: 40px; padding: 0 12px; font-size: 0.85rem; }
  .rtool--icon { width: 40px; padding: 0; }
  .rtool .rtool__label { display: none; }
  .rtool--back { width: 40px; padding: 0; justify-content: center; }
  .reader__tools { gap: 5px; }
  .reader__stage { padding: 6px 10px 64px; }
  .rnav { top: auto; bottom: 8px; width: 48px; height: 48px; translate: none; }
  .reader.is-cover .rnav--next { animation: none; }
  /* The page number moves down between the turn buttons, like a page number in a book. */
  .reader__bar { grid-template-columns: auto minmax(0, 1fr); }
  .reader__where { position: fixed; left: 50%; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 26px); z-index: 4; padding: 0.35em 0.9em; border-radius: 999px; background: rgba(255, 255, 255, 0.75); font-size: 0.85rem; translate: -50% 0; pointer-events: none; }
  .reader:has(.reader__caption:not([hidden])) .reader__where { display: none; }
}
@media (max-width: 380px) {
  .rtool--read span { display: none; }
  .rtool--read { width: 40px; padding: 0; justify-content: center; }
}
/* Phones: the Classic | Immersive switch sits between the page-turn buttons, where the page
   number goes once the book is open. */
@media (max-width: 700px) {
  .reader__versions { bottom: 14px; }
  .vswitch__opt { height: 32px; padding: 0 12px; font-size: 0.85rem; }
}
@media (max-width: 380px) {
  .vswitch__opt .icon { display: none; }
}
/* Short landscape phones: everything tighter so the spread stays big. */
@media (max-height: 480px) and (orientation: landscape) {
  .reader__bar { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 2px; }
  .rtool { height: 36px; }
  .rtool--icon { width: 36px; }
  .vswitch__opt { height: 28px; }
  .reader__stage { padding: 4px clamp(52px, 8vw, 80px) 8px; }
  .rnav { width: 44px; height: 44px; }
  .reader__caption { max-height: 26svh; padding: 8px 16px; font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  .reader__sky .cloud, .rfact, .rcover__open, .reader.is-cover .rnav--next, .rbook__plane { animation: none; }
  .rbook { transition: none; }
}

/* ==========================================================================
   The bookshelf (/library)
   ========================================================================== */
.lib { position: relative; padding: clamp(130px, 16vw, 190px) 0 var(--section); background: linear-gradient(180deg, var(--sky), var(--paper) 70%); overflow: clip; }
.lib__sky .cloud { position: absolute; width: clamp(120px, 15vw, 240px); aspect-ratio: 2; }
.lib__sky .cloud--p1 { top: 14%; left: 4%; }
.lib__sky .cloud--p2 { top: 26%; right: 6%; }
.lib__inner { position: relative; max-width: 60rem; }
.lib__title { margin: 0.8rem 0 1.4rem; }
.lib__lead { max-width: 40rem; font-size: 1.12rem; line-height: 1.6; color: var(--ink-2); }
.lib__lead a { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.lib__state { margin-bottom: 2.4rem; }
.lib__state[data-library-state='loading'] { display: flex; align-items: center; gap: 12px; color: var(--ink-2); }
.lib__plane { width: 32px; height: 32px; color: var(--coral); animation: r-fly 1.6s var(--ease-in-out) infinite; }
.lib__shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1.4rem; margin: 1.6rem 0 2rem; }
.lib__book { display: grid; gap: 0.6rem; padding: 1.2rem; border-radius: var(--radius); background: var(--tint); transition: transform 0.45s var(--ease-spring); }
.lib__book:hover { transform: translateY(-5px) rotate(-1deg); }
.lib__cover img { width: 100%; height: auto; border-radius: 3px 8px 8px 3px; box-shadow: var(--shadow-book); }
.lib__name { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; }
.lib__go { display: inline-flex; align-items: center; gap: 0.4rem; justify-self: start; padding: 0.5em 1.1em; border-radius: 999px; background: var(--coral-deep); color: #fff; font-weight: 700; }
.lib__go .icon { width: 1em; height: 1em; }
.lib__link { max-width: 44rem; padding: 1.2rem 1.4rem; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-sm); }
.lib__link p { color: var(--ink-2); line-height: 1.55; }
.lib__copy { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 0.9rem; }
.lib__copy input { flex: 1 1 260px; min-width: 0; height: 46px; padding: 0 14px; border: 0; border-radius: 14px; background: var(--paper-2); font: inherit; font-size: 0.9rem; color: var(--ink); }
.lib__error { margin: 0 0 1.6rem; padding: 12px 16px; border-radius: 16px; background: var(--blush); font-weight: 600; }
.lib__find { max-width: 44rem; padding: clamp(1.2rem, 3vw, 2rem); border-radius: var(--radius-lg); background: var(--paper-2); }
.lib__h2 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); margin-bottom: 0.5rem; }
.lib__find > p { color: var(--ink-2); line-height: 1.55; }
.lib__fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 1.1rem 0 0.9rem; }
.lib__fields label { display: grid; gap: 6px; flex: 1 1 200px; font-weight: 700; font-size: 0.9rem; }
.lib__fields input { height: 52px; padding: 0 16px; border: 0; border-radius: 16px; background: #fff; font: inherit; font-weight: 500; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line-2); }
.lib__fields input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.lib__help { font-size: 0.92rem; color: var(--ink-3); }
.lib__help a { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
