/* Interactive roadmap book — page flip, parchment pages, chapter spreads. */
@font-face {
    font-family: 'Enjelina Demo';
    src: url('assets/fonts/book/EnjelinaDemo.woff2') format('woff2'),
        url('assets/fonts/book/EnjelinaDemo.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
    /* Improves loading performance */
}


/* Layout rules below would otherwise beat the UA stylesheet's [hidden]. */
.book-main [hidden] {
    display: none !important;
}

.book-main {
    width: 100%;
    padding: 1rem 0 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.book-intro {
    width: min(1140px, 94vw);
    text-align: center;
}

.book-intro h1 {
    font-size: clamp(1.6rem, 3.2vw, 2.4rem);
    margin-bottom: 0.35rem;
}

.book-intro p {
    color: var(--muted);
    line-height: 1.55;
}

/* ---------- stage ---------- */

.book-stage {
    --book-w: min(1140px, 94vw);
    --book-h: min(calc(var(--book-w) * 0.66), 74vh);
    --flip-dur: 900ms;
    --paper: #f8f1e0;
    --paper-edge: #e2d3b4;
    --ink: #2a2318;
    --leather: #1d2a4a;
    --cover: #020202;
    --cover-eyebrow: rgba(66, 66, 66, 0.75);
    --cover-sub: rgba(66, 66, 66, 0.8);
    --cover-hint: rgba(185, 3, 3, 1);
    width: var(--book-w);
    height: var(--book-h);
    position: relative;
    perspective: 2600px;
    perspective-origin: 50% 45%;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: pan-y;
}

/* Native image drag would swallow the pointer stream used for turning pages. */
.book-stage img {
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.book-stage::after {
    content: "";
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: -1.5rem;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(14, 29, 60, 0.28), rgba(14, 29, 60, 0) 70%);
    pointer-events: none;
}

.book {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--flip-dur) cubic-bezier(0.3, 0.1, 0.2, 1);
}

/* Closed book shows only one half, so slide the spine to centre. */
.book.is-closed-front {
    transform: translateX(-25%);
}

.book.is-closed-back {
    transform: translateX(25%);
}

/* Stack of unturned paper behind the right half. */
.book-block {
    position: absolute;
    top: 0.6%;
    height: 98.8%;
    width: 50%;
    border-radius: 4px 10px 10px 4px;
    background: linear-gradient(90deg, #d9c9a6 0%, #f3ead8 22%, #e8dcc0 60%, #cdbb95 100%);
    box-shadow: 0 18px 40px rgba(14, 29, 60, 0.32);
    transform: translateZ(-1px);
}

/* Fading in waits for the leaf to sweep past 90deg; fading out must be instant, or the
   closing cover uncovers a stack that should already be gone. */
.book-block--right {
    left: 50%;
    opacity: 1;
    transition: opacity 220ms ease calc(var(--flip-dur) * 0.5);
}

/* At the back cover the right half is empty, so its paper stack must go. */
.book.is-closed-back .book-block--right {
    opacity: 0;
    transition-delay: 0s;
}

.book-block--left {
    left: 0;
    border-radius: 10px 4px 4px 10px;
    background: linear-gradient(270deg, #d9c9a6 0%, #f3ead8 22%, #e8dcc0 60%, #cdbb95 100%);
    opacity: 0;
    transition: opacity 220ms ease;
}

.book:not(.is-closed-front) .book-block--left {
    opacity: 1;
    transition-delay: calc(var(--flip-dur) * 0.5);
}

.book-spine {
    position: absolute;
    left: calc(50% - 7px);
    top: 0;
    width: 14px;
    height: 100%;
    z-index: 900;
    pointer-events: none;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, rgba(58, 42, 20, 0.32) 40%, rgba(58, 42, 20, 0.32) 60%, rgba(0, 0, 0, 0) 100%);
    opacity: 0;
    transition: opacity 220ms ease;
}

.book:not(.is-closed-front):not(.is-closed-back) .book-spine {
    opacity: 1;
    transition-delay: calc(var(--flip-dur) * 0.5);
}

/* A closed cover with its own artwork must not have the paper stack showing through it. */
.book.is-closed-front:has(.leaf-face.has-bg[data-page-type="cover"]) .book-block--right,
.book.is-closed-back:has(.leaf-face.has-bg[data-page-type="backcover"]) .book-block--left {
    opacity: 0;
    transition-delay: 0s;
}

/* Same for the leaves waiting underneath; hidden only once the turn has finished. */
.book.is-closed-front:has(.leaf-face.has-bg[data-page-type="cover"]) .book-leaf:not(.book-leaf--first),
.book.is-closed-back:has(.leaf-face.has-bg[data-page-type="backcover"]) .book-leaf:not(.book-leaf--last) {
    visibility: hidden;
    transition: transform var(--flip-dur) cubic-bezier(0.3, 0.1, 0.2, 1), visibility 0s linear var(--flip-dur);
}

/* While dragging an edge cover, temporarily reveal underlying leaves/pages. */
.book.is-cover-drag-preview-front .book-leaf,
.book.is-cover-drag-preview-back .book-leaf {
    visibility: visible !important;
    transition-delay: 0s !important;
}

.book.is-cover-drag-preview-front .book-block--right,
.book.is-cover-drag-preview-back .book-block--left {
    opacity: 1 !important;
    transition-delay: 0s !important;
    transition-duration: 0s !important;
}

/* ---------- leaves ---------- */

.book-leaf {
    position: absolute;
    left: 50%;
    top: 0;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform var(--flip-dur) cubic-bezier(0.3, 0.1, 0.2, 1);
}

/* Only the handful of leaves around the current spread need painting. */
.book-leaf.is-far {
    visibility: hidden;
}

.book-leaf.is-flipped {
    transform: rotateY(-180deg);
}

.book-leaf.is-turning,
.book-leaf.is-dragging {
    will-change: transform;
}

.book-leaf.is-dragging {
    transition: none;
}

.book.is-jumping .book-leaf,
.book.is-jumping .book-block {
    transition: none;
}

.leaf-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    background: var(--paper);
    background-image:
        radial-gradient(circle at 18% 22%, rgba(196, 172, 122, 0.16) 0%, rgba(196, 172, 122, 0) 45%),
        radial-gradient(circle at 78% 74%, rgba(150, 120, 70, 0.12) 0%, rgba(150, 120, 70, 0) 50%),
        linear-gradient(180deg, #fbf5e7 0%, #f3e9d3 100%);
    color: var(--ink);
    display: flex;
    flex-direction: column;
}

/* Recto (right) page: gutter shadow on its left edge. */
.leaf-face--front {
    border-radius: 2px 8px 8px 2px;
    box-shadow: inset 14px 0 26px -14px rgba(80, 58, 22, 0.55);
}

/* Verso (left) page lives on the back of the leaf. */
.leaf-face--back {
    transform: rotateY(180deg);
    border-radius: 8px 2px 2px 8px;
    box-shadow: inset -14px 0 26px -14px rgba(80, 58, 22, 0.55);
}

/* Shading that darkens a leaf as it lifts off the stack. */
.leaf-shade {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    z-index: 5;
    background: linear-gradient(90deg, rgba(58, 42, 20, 0.5) 0%, rgba(58, 42, 20, 0) 60%);
    transition: opacity 240ms ease;
}

.leaf-face--back .leaf-shade {
    background: linear-gradient(270deg, rgba(58, 42, 20, 0.5) 0%, rgba(58, 42, 20, 0) 60%);
}

.book-leaf.is-turning .leaf-shade {
    opacity: 1;
}

.leaf-number {
    position: absolute;
    bottom: 0.8rem;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(80, 58, 22, 0.55);
    z-index: 4;
}

.leaf-face--front .leaf-number {
    right: 1.4rem;
}

.leaf-face--back .leaf-number {
    left: 1.4rem;
}

/* ---------- page content ---------- */

.page {
    flex: 1;
    min-height: 0;
    position: relative;
    padding: clamp(1rem, 2.4vw, 2.2rem);
    padding-bottom: 2.2rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.page-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.page h2 {
    font-size: clamp(1.15rem, 1.9vw, 1.7rem);
    color: #241d12;
    line-height: 1.2;
}

.page p {
    font-size: clamp(0.85rem, 1.05vw, 1rem);
    line-height: 1.6;
    color: rgba(42, 35, 24, 0.86);
}

.page p+p {
    margin-top: 0.6rem;
}

.page-lede {
    font-size: clamp(0.95rem, 1.25vw, 1.15rem) !important;
    font-style: italic;
    color: #33291a !important;
}

.page-note {
    font-size: 0.78rem !important;
    color: rgba(42, 35, 24, 0.6) !important;
}

.page-eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(80, 58, 22, 0.7);
}

.page-rule {
    height: 1px;
    background: linear-gradient(90deg, rgba(120, 92, 40, 0.45), rgba(120, 92, 40, 0));
    margin: 0.2rem 0 0.3rem;
}

.page-cta {
    display: inline-block;
    margin-top: 0.6rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
}

/* ---------- cover ---------- */

.page--cover {
    background:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 55%),
        linear-gradient(160deg, #26365d 0%, #16223d 55%, #0d1526 100%);
    color: var(--cover);
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(246, 230, 199, 0.18), inset 0 0 90px rgba(0, 0, 0, 0.5);
}

.page--cover::before {
    content: "";
    position: absolute;
    inset: 5%;
    /* border: 2px solid rgba(246, 230, 199, 0.35); */
    border-radius: 6px;
    pointer-events: none;
    z-index: 2;
}

.page-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

/* Artwork stands on its own: no scrim, no painted gradient, no paper, no inner shadow.
   Content pages keep their paper, so a page image can be a partly transparent overlay. */
.leaf-face.has-bg[data-page-type="cover"],
.leaf-face.has-bg[data-page-type="backcover"] {
    background: none;
    background-color: transparent;
    box-shadow: none;
}

.page--cover.has-bg,
.page--backcover.has-bg {
    background: transparent;
    box-shadow: none;
}

.page.has-bg>*:not(.page-bg) {
    position: relative;
    z-index: 2;
}

.page--cover .cover-eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--cover-eyebrow);
}

.page--cover h1 {
    font-family: "Enjelina Demo";
    font-size: clamp(2.5rem, 4vw, 4rem);
    color: var(--cover);
    line-height: 1.15;
    max-width: 80%;
}

.page--cover .cover-sub {
    font-size: 0.9rem;
    font-style: italic;
    color: var(--cover-sub);
}

.cover-emblem {
    width: clamp(56px, 8vw, 92px);
    height: auto;
    opacity: 0.9;
    margin-bottom: 0.4rem;
}

.cover-hint {
    margin-top: 1.2rem;
    font-size: 0.78rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--cover-hint);
    animation: pulse-badge 2.4s ease-in-out infinite;
}

.page--backcover {
    background: linear-gradient(160deg, #1b2843 0%, #0d1526 100%);
    color: rgba(246, 230, 199, 0.8);
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* .page--blank {
    background: linear-gradient(180deg, #f5edda 0%, #eee2c8 100%);
} */

/* ---------- table of contents ---------- */

.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    overflow-y: auto;
    min-height: 0;
    overflow-x: hidden;
}

.toc-item {
    width: 100%;
    display: grid;
    grid-template-columns: 1.6rem 1fr auto;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.35rem 0.4rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: clamp(0.8rem, 1vw, 0.98rem);
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.toc-item:hover,
.toc-item:focus-visible {
    background: rgba(120, 92, 40, 0.12);
    transform: translateX(3px);
    outline: none;
}

.toc-num {
    font-variant-numeric: tabular-nums;
    color: rgba(80, 58, 22, 0.65);
    font-size: 0.8em;
}

.toc-title {
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.toc-title::after {
    content: " ..........................................................................................";
    color: rgba(80, 58, 22, 0.4);
}

.toc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    align-self: center;
}

.toc-item.is-here .toc-title {
    font-weight: 700;
}

/* ---------- status stamps ---------- */

.stamp {
    position: absolute;
    top: clamp(0.8rem, 2vw, 1.6rem);
    right: clamp(0.8rem, 2vw, 1.6rem);
    z-index: 6;
    padding: 0.35rem 0.7rem;
    border: 3px double currentColor;
    border-radius: 4px;
    font-size: clamp(0.6rem, 0.85vw, 0.78rem);
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    transform: rotate(-11deg);
    opacity: 0.72;
    mix-blend-mode: multiply;
    pointer-events: none;
    white-space: nowrap;
}

.stamp--done {
    color: #2f6b3a;
}

.stamp--in-progress {
    color: #9a5b12;
}

.stamp--planned {
    color: #4a4a52;
    opacity: 0.55;
}

/* ---------- chapter art page ---------- */

.page--art {
    padding: 0;
    position: relative;
    justify-content: flex-end;
}

/* Full-bleed art can cover the inset box-shadow; paint a dedicated gutter shade above it. */
.leaf-face--back[data-page-type="chapter-art"]::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    background: linear-gradient(270deg, rgba(80, 58, 22, 0.28) 0%, rgba(80, 58, 22, 0.12) 8%, rgba(80, 58, 22, 0) 18%);
}

/* Force a real visible gutter cut-in on the spine side (right edge of left page). */
.leaf-face--back[data-page-type="chapter-art"] .page--art {
    padding-right: 7px !important;
}

.leaf-face--back[data-page-type="chapter-art"] .art-frame {
    position: absolute;
    inset: 0 !important;
    border-radius: 8px 2px 2px 8px;
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.16), inset -14px 0 26px -14px rgba(80, 58, 22, 0.5);
}

.leaf-face--back[data-page-type="chapter-art"] .art-layer {
    left: -6%;
    right: -5.2%;
}

.art-frame {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.art-layer {
    position: absolute;
    inset: -6%;
    width: 112%;
    height: 112%;
    object-fit: cover;
    transition: transform 320ms cubic-bezier(0.2, 0.6, 0.2, 1);
    will-change: transform;
}

.art-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(20, 14, 4, 0) 62%, rgba(20, 14, 4, 0.82) 100%);
}

.art-caption {
    position: relative;
    z-index: 3;
    padding: clamp(0.9rem, 2vw, 1.8rem);
    color: var(--paper);
}

.art-caption .page-eyebrow {
    color: var(--cover-hint);
}

.art-caption h2 {
    color: var(--paper);
    margin-top: 0.2rem;
}

.art-missing {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.5rem;
    font-size: 0.85rem;
    color: rgba(80, 58, 22, 0.6);
    background: repeating-linear-gradient(45deg, #efe3c9 0 12px, #e9dcbf 12px 24px);
}

/* ---------- chapter text page ---------- */

.chapter-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.progress {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(80, 58, 22, 0.7);
}

.progress-bar {
    height: 9px;
    border-radius: 999px;
    background: rgba(120, 92, 40, 0.16);
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(80, 58, 22, 0.25);
}

.progress-fill {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #6b5220, #a8813a);
    transition: width 900ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.dev-plan {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.32rem;
}

.dev-plan li {
    position: relative;
    padding-left: 1.05rem;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    line-height: 1.45;
    color: rgba(42, 35, 24, 0.85);
}

.dev-plan li::before {
    content: "\2767";
    position: absolute;
    left: 0;
    color: rgba(120, 92, 40, 0.7);
}

.chapter-quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.42rem;
}

.chapter-quick-link {
    border: 1px solid rgba(120, 92, 40, 0.35);
    background: rgba(255, 255, 255, 0.48);
    color: #3b2d18;
    border-radius: 999px;
    padding: 0.3rem 0.62rem;
    font-family: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

.chapter-quick-link:hover,
.chapter-quick-link:focus-visible {
    background: rgba(255, 255, 255, 0.75);
    transform: translateY(-1px);
    outline: none;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 0.4rem;
}

.gallery img,
.page-video {
    width: 100%;
    border-radius: 6px;
    border: 1px solid rgba(120, 92, 40, 0.35);
    display: block;
}

.track {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid rgba(120, 92, 40, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.4);
}

.track-btn {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    border: 1px solid rgba(120, 92, 40, 0.4);
    background: #fffaf0;
    color: #6b5220;
    cursor: pointer;
    font-size: 0.85rem;
    display: grid;
    place-items: center;
}

.track-btn:hover {
    background: #fff;
}

.track-label {
    font-size: 0.8rem;
    color: rgba(42, 35, 24, 0.8);
    line-height: 1.3;
}


/* ---------- character codex page ---------- */

.character-codex {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.character-codex .page-lede {
    margin-bottom: 0.2rem;
}

.character-codex-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    align-content: start;
    gap: 0.75rem;
}

.scene-codex {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 0;
}

.scene-codex .page-lede {
    margin-bottom: 0.2rem;
}

.scene-page {
    overflow: hidden;
}

.character-card {
    display: grid;
    grid-template-columns: 76px 1fr;
    gap: 0.58rem;
    align-items: center;
    padding: 0.5rem;
    border-radius: 10px;
    border: 1px solid rgba(120, 92, 40, 0.28);
    background: linear-gradient(180deg, rgba(255, 252, 245, 0.9), rgba(248, 238, 214, 0.72));
}

.character-card img {
    width: 76px;
    height: 76px;
    aspect-ratio: 1 / 1;
    border-radius: 7px;
    object-fit: cover;
    border: 1px solid rgba(120, 92, 40, 0.35);
    display: block;
}

.img-fallback-question {
    object-fit: contain;
    background: transparent;
    padding: 0.2rem;
    opacity: 0.92;
}

.character-card h3 {
    font-size: 0.88rem;
    color: #2d2214;
    line-height: 1.15;
}

.character-name-row,
.scene-name-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem;
}

.version-inline {
    color: #b12c2c;
    font-size: 0.88rem;
    line-height: 1.15;
    white-space: nowrap;
}

.character-role {
    margin-top: 0.2rem;
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(80, 58, 22, 0.72);
}

.character-species {
    margin-top: 0.1rem;
    font-size: 0.68rem;
    font-style: italic;
    color: rgba(80, 58, 22, 0.55);
}

.character-card p {
    margin-top: 0.28rem;
    font-size: 0.75rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

.character-meta {
    margin-top: 0.42rem;
    display: flex;
    flex-direction: column;
    gap: 0.32rem;
}

.scene-preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.44rem;
    margin-top: 0.45rem;
}

.scene-preview-card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.34rem;
    align-items: start;
    padding: 0.35rem;
    border-radius: 10px;
    border: 1px solid rgba(120, 92, 40, 0.28);
    background: linear-gradient(180deg, rgba(255, 252, 245, 0.9), rgba(248, 238, 214, 0.72));
}

.scene-preview-pose {
    width: 100%;
    border-radius: 7px;
    border: 1px dashed rgba(120, 92, 40, 0.35);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    background: repeating-linear-gradient(
        135deg,
        rgba(191, 165, 111, 0.16),
        rgba(191, 165, 111, 0.16) 6px,
        rgba(255, 255, 255, 0.25) 6px,
        rgba(255, 255, 255, 0.25) 12px
    );
}

.scene-preview-pose img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.scene-preview-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.28rem;
    align-items: center;
}

.scene-preview-avatars {
    display: flex;
    align-items: center;
}

.scene-preview-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(120, 92, 40, 0.35);
}

.scene-preview-avatars .scene-preview-avatar + .scene-preview-avatar {
    margin-left: -8px;
}

.scene-preview-titlebox {
    min-width: 0;
}

.scene-preview-copy h3 {
    font-size: 0.88rem;
    line-height: 1.2;
    color: #2d2214;
}

.scene-preview-character {
    margin-top: 0.08rem;
    font-size: 0.68rem;
    color: rgba(80, 58, 22, 0.72);
}

.scene-preview-pairing {
    margin-top: 0.12rem;
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(80, 58, 22, 0.72);
}

.scene-preview-copy p {
    margin-top: 0.16rem;
    font-size: 0.75rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.scene-preview-meta {
    margin-top: 0.2rem;
}

.scene-preview-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem;
}

.scene-preview-status {
    display: inline-block;
    padding: 0.12rem 0.36rem;
    border-radius: 999px;
    border: 1px solid rgba(126, 93, 30, 0.34);
    background: rgba(244, 227, 191, 0.58);
    color: #61451f;
    font-size: 0.56rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.scene-preview-posekind {
    display: inline-block;
    padding: 0.12rem 0.36rem;
    border-radius: 999px;
    border: 1px solid rgba(114, 83, 47, 0.34);
    background: rgba(245, 229, 197, 0.72);
    color: #5c3e18;
    font-size: 0.56rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.scene-preview-posekind--handjob {
    border-color: rgba(174, 106, 36, 0.44);
    background: rgba(252, 228, 189, 0.78);
    color: #7a4c17;
}

.scene-preview-posekind--blowjob {
    border-color: rgba(136, 72, 158, 0.44);
    background: rgba(234, 211, 245, 0.78);
    color: #5e2f70;
}

.scene-preview-posekind--cunnilingus {
    border-color: rgba(171, 63, 92, 0.44);
    background: rgba(248, 208, 220, 0.78);
    color: #7b2b44;
}

.scene-preview-posekind--tailjob {
    border-color: rgba(49, 122, 130, 0.44);
    background: rgba(199, 236, 240, 0.78);
    color: #205c63;
}

.scene-preview-posekind--threesome {
    border-color: rgba(126, 86, 162, 0.44);
    background: rgba(223, 210, 241, 0.78);
    color: #583984;
}

.scene-preview-kind {
    display: inline-block;
    padding: 0.12rem 0.36rem;
    border-radius: 999px;
    border: 1px solid rgba(85, 72, 50, 0.34);
    background: rgba(223, 214, 197, 0.62);
    color: #4b3a23;
    font-size: 0.56rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.scene-preview-kind--hetero {
    border-color: rgba(47, 111, 78, 0.4);
    background: rgba(196, 236, 210, 0.72);
    color: #23563a;
}

.scene-preview-kind--homo {
    border-color: rgba(65, 91, 161, 0.4);
    background: rgba(205, 218, 247, 0.72);
    color: #283e79;
}

.scene-preview-kind--lesbian {
    border-color: rgba(170, 78, 58, 0.4);
    background: rgba(246, 214, 202, 0.72);
    color: #7f3727;
}

.scene-preview-kind--threesome,
.scene-preview-kind--group {
    border-color: rgba(133, 81, 150, 0.4);
    background: rgba(231, 211, 240, 0.72);
    color: #5a2f6c;
}

.scene-progress {
    margin-top: 0.18rem;
    gap: 0.14rem;
}

.scene-progress .progress-label {
    font-size: 0.54rem;
}

.scene-progress .progress-bar {
    height: 5px;
}

.character-progress {
    gap: 0.2rem;
}

.character-progress .progress-label {
    font-size: 0.62rem;
}

.character-progress .progress-bar {
    height: 7px;
}

.character-note {
    margin-top: 0.1rem;
    padding-top: 0.5rem;
    border-top: 1px dashed rgba(120, 92, 40, 0.35);
    font-size: 0.75rem;
    color: rgba(42, 35, 24, 0.68);
}

.you-are-here {
    position: absolute;
    top: 0;
    left: clamp(0.9rem, 2.5vw, 2rem);
    z-index: 7;
    padding: 0.9rem 0.5rem 2rem;
    background: #9a2f2f;
    color: #ffeccd;
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    writing-mode: vertical-rl;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 86%, 0 100%);
    pointer-events: none;
}

/* ---------- map page ---------- */

.page--map {
    justify-content: flex-end;
    gap: 0.5rem;
}

.map-above-text {
    font-size: clamp(0.82rem, 1vw, 0.95rem);
    line-height: 1.5;
    color: rgba(42, 35, 24, 0.82);
    margin: 0;
}

.map-frame {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: auto auto 0;
    border-radius: 8px;
    overflow: hidden;
    /* border: 1px solid rgba(120, 92, 40, 0.35); */
}

.map-frame img {
    width: 100%;
    height: auto;
    display: block;
}

.map-routes {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.map-pin {
    position: absolute;
    z-index: 2;
    transform: translate(-50%, -100%);
    padding: 0;
    width: 14px;
    height: 14px;
    border-radius: 50% 50% 50% 0;
    rotate: -45deg;
    background: #9a2f2f;
    border: 2px solid #ffeccd;
    appearance: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    cursor: pointer;
    transition: transform 140ms ease;
}

.map-pin:hover,
.map-pin:focus-visible {
    transform: translate(-50%, -100%) scale(1.35);
}

.map-pin.is-linked-active {
    transform: translate(-50%, -100%) scale(1.35);
    background: #c44343;
}

.map-legend {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: clamp(0.78rem, 1vw, 0.92rem);
}

.map-legend li {
    display: flex;
    align-items: center;
    color: rgba(42, 35, 24, 0.85);
}

.map-legend-link {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.12rem 0.2rem;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 140ms ease, transform 140ms ease;
}

.map-legend-link:hover,
.map-legend-link:focus-visible,
.map-legend-link.is-linked-active {
    background: rgba(120, 92, 40, 0.12);
    transform: translateX(2px);
    outline: none;
}

.map-legend .dotmark {
    width: 9px;
    height: 9px;
    flex: none;
    border-radius: 50%;
    background: #9a2f2f;
}

.map-legend-link.is-linked-active .dotmark {
    background: #c44343;
}

/* ---------- bookmarks ---------- */

.bookmarks {
    position: absolute;
    right: -0.4rem;
    top: 8%;
    z-index: 950;
    display: flex;
    flex-direction: column;
    gap: 4px;
    list-style: none;
    opacity: 1;
    /* Tabs wait out the opening flip, but leave the instant the book starts to close. */
    transition: opacity 220ms ease var(--flip-dur);
}

.book-stage.is-closed .bookmarks {
    opacity: 0;
    transition-delay: 0s;
    pointer-events: none;
}

.bookmark {
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 0 4px 4px 0;
    background: #c9b489;
    color: #3a2a14;
    font-size: 0.68rem;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.22);
    transition: transform 0.16s ease, background-color 0.16s ease, width 0.16s ease;
}

.bookmark:hover,
.bookmark:focus-visible {
    transform: translateX(5px);
    background: #dcc79c;
    outline: none;
}

.bookmark.is-active {
    background: #9a2f2f;
    color: #ffeccd;
    transform: translateX(5px);
}

/* ---------- controls ---------- */

.book-controls {
    width: min(1140px, 94vw);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.book-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.95rem;
    border: 0;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(14, 29, 60, 0.18);
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.book-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.book-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.book-progress {
    font-size: 0.82rem;
    color: var(--muted);
    min-width: 7rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.book-volume {
    width: 90px;
    accent-color: var(--primary);
}

.book-main.is-fullscreen {
    width: 100%;
    min-height: 100vh;
    padding: 0.75rem;
    justify-content: center;
    background-image: var(--book-fullscreen-bg, radial-gradient(circle at top, rgba(36, 55, 96, 0.2) 0%, rgba(15, 21, 38, 0.96) 68%));
    background-size: var(--book-fullscreen-bg-size, auto);
    background-position: var(--book-fullscreen-bg-position, center center);
    background-repeat: var(--book-fullscreen-bg-repeat, no-repeat);
    background-blend-mode: var(--book-fullscreen-bg-blend, normal);
}

.book-main.is-fullscreen .book-controls {
    display: none;
}

.book-main.is-fullscreen .book-intro {
    opacity: 0;
    height: 0;
    overflow: hidden;
    margin: 0;
}

.book-main.is-fullscreen .book-stage {
    --book-w: min(95vw, var(--book-fs-max-w, 1500px));
    --book-h: min(92vh, calc(var(--book-w) * 0.66));
}

.book-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- loading / error ---------- */

.book-loading {
    display: grid;
    place-items: center;
    height: 100%;
    width: 100%;
    color: var(--muted);
    font-style: italic;
}

/* ---------- fallback (no JS / load failure) ---------- */

.book-fallback {
    width: min(960px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.book-fallback article {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    background: linear-gradient(180deg, #fbf5e7 0%, #ffffff 100%);
}

.book-fallback h2 {
    font-size: 1.05rem;
    margin-bottom: 0.3rem;
}

.book-fallback p {
    color: var(--muted);
    line-height: 1.55;
    font-size: 0.94rem;
}

/* ---------- portrait / single page mode ---------- */

.book-stage.is-portrait {
    --book-h: min(calc(var(--book-w) * 1.42), 72vh);
}

.book-stage.is-portrait .book,
.book-stage.is-portrait .book-block,
.book-stage.is-portrait .book-spine {
    display: none;
}

.portrait-stage {
    position: relative;
    width: 100%;
    height: 100%;
    perspective: 2600px;
    perspective-origin: left center;
    transform-style: preserve-3d;
    overflow: hidden;
    display: none;
}

.book-stage.is-portrait .portrait-stage {
    display: block;
}

.portrait-page {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--paper);
}

.portrait-page--under {
    z-index: 1;
}

/* The turning sheet: hiding its backface reveals the page waiting underneath. */
.portrait-page--top {
    z-index: 2;
    transform-origin: 0% 50%;
    transform-box: border-box;
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: 0 18px 40px rgba(14, 29, 60, 0.32);
}

/* Masks tiny subpixel seams that can reveal the next page before the turn completes. */
/* .portrait-page--under {
    clip-path: inset(0 0 0 1px);
} */

.portrait-page--top::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 9;
    background: rgba(58, 42, 20, 0.6);
    opacity: 0;
    pointer-events: none;
}

.portrait-page>.leaf-face {
    border-radius: 8px;
    box-shadow: none;
    backface-visibility: visible;
    -webkit-backface-visibility: visible;
    transform: none !important;
}

.portrait-page--top.is-turning-next {
    animation: portrait-turn-next var(--flip-dur) cubic-bezier(0.42, 0.02, 0.3, 1) forwards;
}

.portrait-page--top.is-turning-prev {
    animation: portrait-turn-prev var(--flip-dur) cubic-bezier(0.42, 0.02, 0.3, 1) forwards;
}

.portrait-page--top.is-turning-next::after,
.portrait-page--top.is-turning-prev::after {
    animation: portrait-shade var(--flip-dur) ease;
}

@keyframes portrait-turn-next {
    from {
        transform: rotateY(0deg);
    }

    to {
        transform: rotateY(-180deg);
    }
}

@keyframes portrait-turn-prev {
    from {
        transform: rotateY(-180deg);
    }

    to {
        transform: rotateY(0deg);
    }
}

@keyframes portrait-shade {
    0% {
        opacity: 0;
    }

    70% {
        opacity: 0.55;
    }

    100% {
        opacity: 0;
    }
}

/* ---------- responsive ---------- */

@media (max-width: 768px) {
    .book-stage {
        --book-w: min(560px, 92vw);
    }

    .bookmarks {
        display: none;
    }

    /* Phone layout uses tap/swipe navigation; hide control row to free vertical room. */
    .book-controls {
        display: none;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    .book-main {
        padding: 0.25rem 0 0.6rem;
        gap: 0.65rem;
    }

    .book-intro {
        width: min(1140px, 96vw);
    }

    .book-intro h1 {
        font-size: clamp(1.1rem, 2vw, 1.4rem);
        margin-bottom: 0.1rem;
    }

    .book-intro p {
        display: none;
    }

    .book-stage {
        /* Landscape phone: use full viewport width for a desktop-like spread. */
        --book-w: 100vw;
        --book-h: calc(var(--book-w) * 0.66);
    }
}

@media (prefers-reduced-motion: reduce) {
    .book-stage {
        --flip-dur: 1ms;
    }

    .book-leaf,
    .book,
    .art-layer,
    .progress-fill {
        transition-duration: 1ms !important;
    }

    .cover-hint {
        animation: none;
    }

    .portrait-page--top.is-turning-next,
    .portrait-page--top.is-turning-prev {
        animation: none;
    }
}