/* =========================================================
   Pemkie Island — Trainer's Journal
   A hand-drawn book, matching the in-game journal UI
   ========================================================= */
:root {
  --line: #9b2c22;        /* red-brown ink of the in-game journal */
  --line-soft: rgba(155, 44, 34, .35);
  --paper: #f8f0df;
  --paper-2: #efe2c8;
  --ink: #4a2a20;
  --nature: #5aa33d;
  --water: #3d9be0;
  --fire: #f0782b;
  --spirit: #8a5cd6;
  --steam: #1b2838;
  --patreon: #ff424d;

  /* Paper texture: fine grain + soft stains, generated SVG noise tiled over the paper colour */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .22  0 0 0 0 .1  0 0 0 .2 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
  --stains: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='640' height='640'><filter id='s'><feTurbulence type='fractalNoise' baseFrequency='.012' numOctaves='3' seed='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .55  0 0 0 0 .38  0 0 0 0 .18  0 0 0 .16 0'/></filter><rect width='100%25' height='100%25' filter='url(%23s)'/></svg>");

  --font-ui: "Fredoka", system-ui, sans-serif;
  --font-title: "Slackey", "Fredoka", system-ui, sans-serif;   /* titles: chunky, like the Pemkie Island logo */
  --font-hand: "Patrick Hand", "Comic Sans MS", cursive;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100svh;
  display: flex; flex-direction: column; justify-content: center;
  font-family: var(--font-hand); font-size: 20px; line-height: 1.35;
  color: var(--ink); background: #6f8f4e;
  overflow-x: hidden;
}
img, video { max-width: 100%; display: block; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px dashed var(--line); outline-offset: 3px; }

/* Blurred island behind the book, like the game's pause screen */
.backdrop {
  position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(rgba(240, 236, 200, .45), rgba(120, 150, 80, .35)),
    url("../assets/bg-blur.jpg") center / cover no-repeat;
}

/* ---------------------------------------------------------
   The book
   --------------------------------------------------------- */
.book {
  --tabs: 198px;
  /* The book is laid out at one fixed design size (art ratio 1297x811) and the whole thing is
     zoomed to fit the window (js: fitBook), so changing section never changes its size. */
  --bw: 1260px;
  position: relative;
  width: var(--bw);
  margin: 24px auto 0;
  translate: calc(var(--tabs) / -2) 0;
  zoom: var(--zoom, 1);
}

.pages {
  position: relative; z-index: 1; /* above the edge tabs, so they tuck under the page */
  display: grid;
  height: calc(var(--bw) * 811 / 1297);
  grid-template-rows: minmax(0, 1fr);   /* spreads never grow the book */
  perspective: 2200px;
  /* The book art (open book over its green cover, 1297x811). The box has the art's exact ratio,
     so it's one background over the whole box (a 9-slice border-image left hairline seams);
     the transparent border is only the cover's margin around the paper. */
  border: solid transparent;
  border-width: calc(var(--bw) * 50 / 1297) calc(var(--bw) * 110 / 1297) calc(var(--bw) * 95 / 1297);
  background: url("../assets/book/book-spread.webp") border-box 0 0 / 100% 100% no-repeat;
  filter: drop-shadow(0 26px 30px rgba(40, 30, 10, .35));
}

.spread { grid-area: 1 / 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.page { position: relative; padding: 18px 34px 76px; min-width: 0; min-height: 0; }
/* Game pages: content centred vertically on the page */
.spread[data-spread^="game"] .page { display: grid; align-content: center; }

/* Section tabs sticking out of the book's right edge */
.bookmarks { position: absolute; z-index: 0; top: 70px; left: calc(100% - var(--bw) * 22 / 1297); width: var(--tabs); display: grid; gap: 8px; }
/* Cel-shaded like the book art: its dark outline, a light edge on top, a darker band at the
   bottom, and a shadow where the tab tucks under the cover. Text sits at the free (right) end. */
.bookmark {
  --outline: #4a4e47;
  font-family: var(--font-title); font-weight: 400; font-size: 15px; letter-spacing: .03em; text-transform: uppercase; text-decoration: none;
  text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 11px 15px 13px 30px; border: 3px solid var(--outline); border-left: 0; border-radius: 0 14px 14px 0;
  background:
    linear-gradient(to right, rgba(35, 40, 30, .38), rgba(35, 40, 30, 0) 38px),
    var(--grain), var(--tab, var(--paper-2));
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .38),
    inset 0 -6px 0 rgba(30, 30, 20, .16),
    0 3px 0 rgba(35, 40, 30, .28);
  color: var(--tab-ink, var(--line)); text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
  transform: translateX(-14px); transition: transform .2s, filter .2s;
}
.bookmark:hover { transform: translateX(-4px); }
.bookmark[aria-current="page"] { transform: translateX(0); }
.bookmark:not([aria-current]):not(.bm-special) { filter: saturate(.7) brightness(.95); }
.bm-game        { --tab: #f6c844; --tab-ink: #8a4f0c; }
.bm-dex         { --tab: #9ccf72; --tab-ink: #33621f; }
.bm-leaderboard { --tab: #7cc0ee; --tab-ink: #1f4f7a; }
.bm-special     { --tab-ink: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.bm-steam       { --tab: var(--steam); margin-top: 14px; }
.bm-patreon     { --tab: var(--patreon); }

/* Ribbon bookmark top-left: back to MESHUP */
.ribbon {
  position: absolute; z-index: 3; top: -6px; left: calc(var(--bw) * 130 / 1297); width: 46px; height: 74px;
  background: var(--line); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  display: grid; justify-items: center; padding-top: 14px;
  transition: height .25s;
}
.ribbon:hover { height: 86px; }
.ribbon img { width: 26px; filter: brightness(0) invert(1); }

/* Headings */
.page-title { margin: 0 0 6px; }
.title-logo { width: min(290px, 66%); margin-inline: auto; filter: drop-shadow(0 4px 0 rgba(155, 44, 34, .25)); }
.page-heading {
  margin: 0 0 18px; text-align: center;
  font-family: var(--font-title); font-weight: 400; font-size: clamp(24px, 2.4vw, 32px); color: var(--line);
}
.note { margin: 0 0 20px; font-size: 23px; }
.note.small { font-size: 18px; text-align: center; color: var(--line); }

/* Taped photo */
.polaroid {
  position: relative; margin: 14px auto 0; width: min(300px, 74%);
  background: #fff; padding: 10px; border: 2px solid var(--line-soft);
  box-shadow: 4px 6px 0 rgba(155, 44, 34, .18);
}
.polaroid img { aspect-ratio: 4 / 4.4; object-fit: cover; object-position: 50% 20%; width: 100%; }
.polaroid::before, .taped-video::before {
  content: ""; position: absolute; top: -12px; left: 50%; width: 84px; height: 24px; translate: -50% 0; rotate: -4deg;
  background: rgba(240, 220, 160, .8); border: 1px dashed rgba(155, 44, 34, .3);
}
.tilt-l { rotate: -3deg; }


.taped-video { position: relative; margin: 0 0 16px; padding: 8px; background: #fff; border: 2px solid var(--line-soft); rotate: 1.5deg; }
.taped-video video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }

/* Game spreads: trailer, big taped clips and the shared bottom bar */
.spread { position: relative; }
/* Pemkie stickers stuck on the pages (game renders, white die-cut border) */
.sticker {
  position: absolute; z-index: 2; width: var(--w, 120px); height: auto; rotate: var(--r, 0deg);
  pointer-events: none; filter: drop-shadow(1px 3px 2px rgba(60, 30, 10, .3));
}
.page:has(> .clip) { display: grid; place-items: center; }
.clip { width: 100%; margin: 0; }
.clip figcaption { text-align: center; color: var(--line); font-size: 20px; padding-top: 6px; }
.yt iframe { display: block; width: 100%; aspect-ratio: 16 / 9; border: 0; }
.game-nav {
  position: absolute; left: 28px; right: 28px; bottom: 18px; z-index: 1;
  display: grid; grid-template-columns: 1fr 1fr; align-items: center;
}
.game-nav .prev { grid-column: 1; grid-row: 1; justify-self: start; }
.game-nav .disclaimer { grid-column: 2; grid-row: 1; justify-self: center; max-width: calc(100% - 120px); }
.game-nav .next { grid-column: 2; grid-row: 1; justify-self: end; }
.disclaimer { margin: 0; font-style: italic; font-size: 16px; color: var(--line); opacity: .55; text-align: center; }

/* Corner page arrows (curled notes in the game UI) */
.corner-nav { position: absolute; left: 28px; right: 28px; bottom: 18px; display: flex; align-items: center; justify-content: space-between; }
/* Sticky-note page buttons */
.corner {
  width: 58px; height: 55px; padding: 0; border: 0; font-size: 0;
  background: url("../assets/book/note-next.webp") center / contain no-repeat;
  filter: drop-shadow(2px 3px 2px rgba(60, 30, 10, .25));
  transition: transform .15s;
}
.corner.prev { background-image: url("../assets/book/note-prev.webp"); }
.corner:hover:not(:disabled) { transform: rotate(-6deg) scale(1.08); }
.corner:disabled { opacity: .35; filter: grayscale(.6); cursor: default; }
.page-num { color: var(--line); }

/* ---------------------------------------------------------
   Dex
   --------------------------------------------------------- */
.dex-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; max-width: 420px; margin: 0 auto; }
.dex-slot {
  position: relative; aspect-ratio: 1; padding: 0; overflow: hidden;
  border: 2.5px solid var(--line); border-radius: 12px; background: var(--paper-2);
  transition: transform .2s;
}
.dex-slot:hover { transform: rotate(-3deg) scale(1.04); }
.dex-slot[aria-selected="true"] { box-shadow: 0 0 0 4px var(--paper), 0 0 0 7px var(--line); transform: rotate(-2deg); }
.dex-slot img { width: 100%; height: 100%; object-fit: contain; padding: 10%; }
.dex-slot .num { position: absolute; left: 6px; top: 3px; font-family: var(--font-ui); font-weight: 700; font-size: 12px; color: var(--line); }
.dex-slot.unknown { display: grid; place-items: center; cursor: default; }
.dex-slot.unknown:hover { transform: none; }
.dex-slot.unknown .num { color: var(--line-soft); }
.dex-slot .sil { position: absolute; inset: 0; padding: 14% 14% 24%; opacity: .9; }
.qqq { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-family: var(--font-ui); font-weight: 700; font-size: 13px; letter-spacing: .15em; color: var(--line-soft); }
.unknown-mark { width: 40%; aspect-ratio: 1; margin-bottom: 14%; border: 2.5px dashed var(--line-soft); border-radius: 12px; display: grid; place-items: center; color: var(--line-soft); font-family: var(--font-ui); font-weight: 700; font-size: 20px; }
.dex-empty { grid-column: 1 / -1; text-align: center; color: var(--line); opacity: .7; margin: 30px 0; }
.dex-slot.more { display: grid; place-items: center; grid-column: span 2; aspect-ratio: auto; border-style: dashed; font-family: var(--font-hand); font-size: 26px; color: var(--line); rotate: -2deg; }

/* Right page: the selected Pemkie in 3D */
/* the 3D view takes whatever height the text leaves on the page */
.spread[data-spread="dex"] .page-right { display: flex; flex-direction: column; }
.dex-entry { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.dex-stage {
  position: relative; width: 100%; flex: 1 1 0; min-height: 190px;
  border: 2px dashed var(--line-soft); border-radius: 18px;
  background: radial-gradient(ellipse at 50% 85%, rgba(155, 44, 34, .08), transparent 60%);
}
.dex-stage canvas, .dex-stage .canvas-still { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.dex-stage canvas:active { cursor: grabbing; }
/* Fan design credit: Reddit sticker on the viewer's top-right corner, details on hover / tap */
.credit { position: absolute; z-index: 3; top: -14px; right: -12px; }
.credit[hidden] { display: none; }
.credit-badge {
  display: block; width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: #fff; box-shadow: 0 0 0 3px #fff; rotate: 12deg;
  filter: drop-shadow(1px 3px 2px rgba(60, 30, 10, .3)); transition: rotate .2s, scale .2s;
}
.credit-badge svg { display: block; width: 100%; height: 100%; }
.credit:hover .credit-badge, .credit.open .credit-badge, .credit-badge:focus-visible { rotate: 0deg; scale: 1.08; }
.credit-pop {
  position: absolute; top: calc(100% + 8px); right: 4px; width: 230px; padding: 10px 12px;
  background: var(--paper-2); border: 2.5px solid var(--line); border-radius: 12px;
  font-size: 16px; line-height: 1.3; text-align: left; color: var(--ink, #3a2a1a);
  box-shadow: 3px 4px 0 rgba(60, 30, 10, .18);
  opacity: 0; visibility: hidden; translate: 0 -4px; transition: opacity .15s, translate .15s, visibility .15s;
}
.credit-pop::before {   /* invisible bridge so the pointer can reach the link */
  content: ""; position: absolute; left: 0; right: 0; top: -12px; height: 12px;
}
.credit-pop a { color: var(--line); font-weight: 700; }
.credit:hover .credit-pop, .credit.open .credit-pop, .credit:focus-within .credit-pop { opacity: 1; visibility: visible; translate: 0 0; }
.dex-stage[data-state="loading"]::after { content: "Taming…"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--line); opacity: .6; }
.dex-info { display: grid; gap: 8px; justify-items: center; }
.dex-name { margin: 0; font-family: var(--font-title); font-weight: 400; font-size: 30px; color: var(--line); }
.dex-name small { font-size: 16px; opacity: .7; margin-left: 6px; }
/* Name row: the element pill (game's own element icons) before the name */
.dex-title { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.type-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 4px; border-radius: 999px;
  font-family: var(--font-ui); font-weight: 600; font-size: 15px; color: #fff;
  background: var(--pill, var(--line)); border: 2px solid rgba(30, 20, 30, .25);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15);
}
/* the game's element glyphs, tinted through a mask */
.type-icon {
  display: inline-block; width: 24px; height: 24px; flex: none; background: var(--tc, currentColor);
  -webkit-mask-position: center; mask-position: center; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}
.type-pill { padding-left: 8px; }
.type-pill .type-icon { width: 20px; height: 20px; }
.side-tab[aria-selected="true"] .type-icon { background: #fff; }
.t-ether { --pill: #9b8fe0; }
.t-fire  { --pill: #ee6a22; }
.t-earth { --pill: #4fae3d; }
.t-water { --pill: #3d9be0; }
.t-rumor { --pill: #b77ad0; }
.dex-desc { margin: 0; text-align: center; font-size: 18px; line-height: 1.28; max-width: 44ch; }
/* Trait: the Pemkie's passive, in its own labelled box */
.dex-trait {
  position: relative; width: min(100%, 440px); margin-top: 10px; padding: 16px 16px 10px;
  border: 2.5px solid var(--line); border-radius: 14px; background: rgba(239, 226, 200, .55); text-align: center;
}
.dex-trait-label {
  position: absolute; top: -12px; left: 50%; translate: -50% 0; padding: 1px 12px; border-radius: 999px;
  font-family: var(--font-ui); font-weight: 700; font-size: 13px; letter-spacing: .14em; color: #fff; background: var(--line);
}
.dex-trait h4 { margin: 0 0 2px; font-family: var(--font-title); font-weight: 400; font-size: 18px; color: var(--line); }
.dex-trait p { margin: 0; font-size: 17px; line-height: 1.3; }
.trait-icon { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: -.28em; object-fit: contain; }

/* Type filters: a row of little tabs above the Dex grid */
.side-tabs { display: flex; justify-content: center; gap: 8px; margin: -4px 0 18px; }
.side-tab {
  width: 46px; height: 46px; padding: 0; display: grid; place-items: center;
  border: 3px solid var(--line); border-radius: 12px;
  background: var(--grain), var(--paper-2); transition: transform .2s, background .2s;
}
.side-tab svg { width: 24px; height: 24px; }
.side-tab:hover { transform: translateY(-3px); }
.side-tab[aria-selected="true"] { background: var(--line); transform: translateY(-3px); }
.side-tab[aria-selected="true"] svg { --c: #fff !important; }

/* ---------------------------------------------------------
   Leaderboard
   --------------------------------------------------------- */
.coming-soon {
  margin: 130px auto 0; width: fit-content; padding: 14px 30px; rotate: -4deg; white-space: nowrap;
  font-family: var(--font-title); font-size: 46px; letter-spacing: .04em; color: var(--line);
  border: 4px solid var(--line); border-radius: 16px; background: var(--paper-2);
}
@media (max-width: 860px) {
  .coming-soon { margin: 40px auto 30px; padding: 10px 20px; font-size: 26px; }
  .page-right:empty { display: none; }
  .sticker { width: calc(var(--w, 120px) * .62); }
  /* clip pages are just photo + caption on the notepad: tuck the sticker in the bottom corner */
  .page:has(> .clip):has(> .sticker) { padding-bottom: 58px; }
  .page:has(> .clip) > .sticker { width: calc(var(--w, 120px) * .5); inset: auto 8px 4px auto !important; }
}

/* ---------------------------------------------------------
   Page flip leaf
   --------------------------------------------------------- */
.leaf {
  position: absolute; z-index: 4; top: 0; bottom: 0; width: 50%; display: none;
  transform-style: preserve-3d; pointer-events: none;
}
.leaf-front, .leaf-back {
  position: absolute; inset: 0; backface-visibility: hidden; background: var(--paper);
  border: 3px solid var(--line);
}
.leaf-back { transform: rotateY(180deg); }
.leaf.fwd { display: block; left: 50%; transform-origin: left center; animation: flip-fwd .7s cubic-bezier(.45, .05, .35, 1) forwards; }
.leaf.fwd .leaf-front { border-radius: 0 19px 19px 0; background: var(--grain), linear-gradient(to right, rgba(120,70,30,.18), transparent 30%), var(--paper); }
.leaf.fwd .leaf-back  { border-radius: 19px 0 0 19px; background: var(--grain), linear-gradient(to left, rgba(120,70,30,.18), transparent 30%), var(--paper); }
.leaf.back { display: block; left: 0; transform-origin: right center; animation: flip-back .7s cubic-bezier(.45, .05, .35, 1) forwards; }
.leaf.back .leaf-front { border-radius: 19px 0 0 19px; background: var(--grain), linear-gradient(to left, rgba(120,70,30,.18), transparent 30%), var(--paper); }
.leaf.back .leaf-back  { border-radius: 0 19px 19px 0; background: var(--grain), linear-gradient(to right, rgba(120,70,30,.18), transparent 30%), var(--paper); }
@keyframes flip-fwd  { from { transform: rotateY(0); } to { transform: rotateY(-180deg); } }
@keyframes flip-back { from { transform: rotateY(0); } to { transform: rotateY(180deg); } }

/* Desktop page turn: hinged strips carrying copies of the real pages */
.turn-under, .turn-sheet { position: absolute; z-index: 5; pointer-events: none; }
.turn-under { overflow: hidden; background-repeat: no-repeat; }
.turn-sheet { transform-style: preserve-3d; }
.turn-strip { position: absolute; top: 0; height: 100%; transform-style: preserve-3d; }
.turn-sheet.fwd  .turn-strip { left: 0;  transform-origin: left center; }
.turn-sheet.back .turn-strip { right: 0; transform-origin: right center; }
.turn-strip .turn-strip { left: auto; right: auto; }
.turn-sheet.fwd  .turn-strip .turn-strip { left: 100%; }
.turn-sheet.back .turn-strip .turn-strip { right: 100%; }
/* faces carry the page art (rounded corners, curled tip come from its transparency); a hair wider to hide seams */
.turn-face {
  position: absolute; inset: 0 -0.6px; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden;   /* 0.6px = BLEED in main.js */
  background-repeat: no-repeat;
}
.turn-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(var(--dir), rgba(60, 30, 10, var(--sh, 0)), rgba(60, 30, 10, var(--so, 0)));
  mask-repeat: no-repeat; -webkit-mask-repeat: no-repeat;
}
/* --sh = shade at the strip's hinge side, --so = at its outer side; the back face is mirrored */
.turn-sheet.fwd .front .turn-shade, .turn-sheet.back .back  .turn-shade { --dir: to right; }
.turn-sheet.fwd .back  .turn-shade, .turn-sheet.back .front .turn-shade { --dir: to left; }
.turn-face.back { transform: rotateY(180deg); }
.yt-still { aspect-ratio: 16 / 9; background: #1d1d1d; }

/* Footer */
.credits { text-align: center; padding: 26px 16px 30px; font-size: 16px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.5); }

/* ---------------------------------------------------------
   Phones / narrow screens: a spiral-bound notepad instead of the book art.
   Sections are sticky notes stuck above the pad; pages flip up over the spiral.
   --------------------------------------------------------- */
@media (max-width: 860px) {
  body { display: block; }
  .book {
    --bw: calc(100vw - 32px); --rule: 30px; --margin: 30px;
    width: var(--bw); margin-top: 14px; zoom: 1; translate: none;
  }

  /* the pad: ruled paper with a red margin line, a few sheets peeking out underneath */
  .pages {
    height: auto; grid-template-rows: auto; margin-top: 18px;
    border: 0; border-image: none; border-radius: 4px 4px 10px 10px;
    background:
      linear-gradient(to right, transparent calc(var(--margin) - 1px), rgba(214, 70, 60, .45) calc(var(--margin) - 1px) calc(var(--margin) + 1px), transparent 0),
      repeating-linear-gradient(to bottom, transparent 0 calc(var(--rule) - 1.5px), rgba(70, 130, 190, .22) calc(var(--rule) - 1.5px) var(--rule)),
      #fdf8ec;
    background-position: 0 0, 0 34px;
    box-shadow: 0 3px 0 -1px #eadfc6, 0 6px 0 -2px #ddd0b3, 0 9px 0 -3px #d2c3a3;
    filter: drop-shadow(0 14px 18px rgba(40, 30, 10, .3));
  }
  /* spiral binding: coils dropping into punched holes along the top edge */
  .pages::before {
    content: ""; position: absolute; z-index: 6; left: 10px; right: 10px; top: -15px; height: 34px; pointer-events: none;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='34'><circle cx='12' cy='25' r='4.2' fill='%233a2418' fill-opacity='.85'/><rect x='9' y='1.5' width='6' height='25' rx='3' fill='%23d9dcdf' stroke='%23656b70' stroke-width='1.3'/><rect x='10.6' y='4' width='1.6' height='19' rx='.8' fill='%23fff' fill-opacity='.7'/></svg>") center top / 24px 34px repeat-x;
  }

  .spread { grid-template-columns: 1fr; }
  .page { padding: 34px 14px 74px calc(var(--margin) + 10px); }
  .page-left:not(:has(.corner-nav)) { padding-bottom: 26px; }
  /* tear-off perforation between the two halves of a spread */
  .page-right { border-top: 3px dotted rgba(155, 44, 34, .3); }
  .spread[data-spread^="game"] .page-right { padding-top: 30px; }
  .credit { top: -10px; right: -6px; }
  .credit-badge { width: 42px; height: 42px; }
  .dex-stage { flex: none; height: 300px; background-color: rgba(248, 240, 223, .7); }

  /* section tabs: sticky notes stuck above the pad */
  .bookmarks {
    position: relative; z-index: 3; top: auto; left: auto; width: auto;
    display: flex; justify-content: center; gap: 1.4cqw; padding: 0; container-type: inline-size;
  }
  .bookmark .ext { display: none; }
  .bookmark {
    font-size: clamp(8px, 3.1cqw, 13px); letter-spacing: 0; text-align: center; overflow: visible;
    padding: 9px 1.8cqw 8px; border: 0; border-radius: 2px;
    background: var(--grain), var(--tab, var(--paper-2));
    box-shadow: 0 2px 0 rgba(0, 0, 0, .08), 2px 4px 6px rgba(40, 30, 10, .25);
    transform: rotate(var(--tilt, -2deg)); transition: transform .2s, filter .2s;
  }
  .bookmark:nth-child(2n) { --tilt: 2deg; }
  .bookmark:nth-child(3n) { --tilt: -1deg; }
  .bookmark:hover { transform: rotate(0) translateY(-2px); }
  .bookmark[aria-current="page"] { transform: rotate(0) translateY(-3px) scale(1.06); filter: none; outline: 2.5px solid var(--line); outline-offset: -2.5px; }
  .bookmark:not([aria-current]):not(.bm-special) { filter: saturate(.75) brightness(.97); }
  .bm-steam { margin-top: 0; margin-left: 1.6cqw; }

  /* MESHUP ribbon: hangs from the spiral on the right (top: auto = right where the pad starts) */
  .ribbon { left: auto; right: 16px; top: auto; margin-top: 22px; width: 40px; height: 62px; padding-top: 14px; z-index: 5; }
  .ribbon:hover { height: 70px; }
  .ribbon img { width: 22px; }

  .game-nav { left: 14px; right: 14px; grid-template-columns: 1fr; }
  .game-nav .prev, .game-nav .disclaimer, .game-nav .next { grid-column: 1; }
  .disclaimer { font-size: 14px; }
  .note { font-size: 19px; line-height: var(--rule); }

  /* page flip: a ruled sheet flips up over the spiral */
  .leaf.fwd, .leaf.back { left: 0; width: 100%; transform-origin: center top; animation-name: flip-up; }
  .leaf .leaf-front, .leaf .leaf-back {
    border: 0; border-radius: 4px 4px 10px 10px !important;
    background:
      linear-gradient(to right, transparent calc(var(--margin) - 1px), rgba(214, 70, 60, .45) calc(var(--margin) - 1px) calc(var(--margin) + 1px), transparent 0),
      repeating-linear-gradient(to bottom, transparent 0 calc(var(--rule) - 1.5px), rgba(70, 130, 190, .22) calc(var(--rule) - 1.5px) var(--rule)),
      #fdf8ec !important;
    box-shadow: 0 6px 14px rgba(40, 30, 10, .25);
  }
  @keyframes flip-up { from { transform: rotateX(0); } to { transform: rotateX(180deg); } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
