/* Wear is confined to material layers; the content and tabs retain their shape. */
#museum-app .museum-product {
  --paper-radius: 8px;
  --edge-top: url('/museum/assets/wear/edge-top.svg');
  --edge-bottom: url('/museum/assets/wear/edge-bottom.svg');
  --edge-left: url('/museum/assets/wear/edge-left.svg');
  --edge-right: url('/museum/assets/wear/edge-right.svg');
  --wear-origin: 0%;
  --wear-offset: 1;
  --left-corner-cut: .7px;
  --right-corner-cut: 1.4px;
  --paper-corners: url('/museum/assets/wear/paper-corners.svg');
  --cover-corners: url('/museum/assets/wear/cover-corners.svg');
}
#museum-app .museum-product[dir='rtl'] {
  --paper-radius: 8px;
  --edge-top: url('/museum/assets/wear/edge-top-rtl.svg');
  --edge-bottom: url('/museum/assets/wear/edge-bottom-rtl.svg');
  --edge-left: url('/museum/assets/wear/edge-left-rtl.svg');
  --edge-right: url('/museum/assets/wear/edge-right-rtl.svg');
  --wear-origin: 100%;
  --wear-offset: -1;
  --left-corner-cut: 1.4px;
  --right-corner-cut: .7px;
  --paper-corners: url('/museum/assets/wear/paper-corners-rtl.svg');
  --cover-corners: url('/museum/assets/wear/cover-corners-rtl.svg');
}
#museum-app .bound-volume::after,
#museum-app .leaf-surface,
#museum-app .section-leaf,
#museum-app .paper-stack::before,
#museum-app .paper-stack::after {
  -webkit-mask-image: linear-gradient(#000, #000), var(--edge-top), var(--edge-bottom), var(--edge-left), var(--edge-right);
  mask-image: linear-gradient(#000, #000), var(--edge-top), var(--edge-bottom), var(--edge-left), var(--edge-right);
  -webkit-mask-size: calc(100% - 8px) calc(100% - 8px), 263px 8px, 263px 8px, 8px 397px, 8px 397px;
  mask-size: calc(100% - 8px) calc(100% - 8px), 263px 8px, 263px 8px, 8px 397px, 8px 397px;
  -webkit-mask-repeat: no-repeat, repeat-x, repeat-x, repeat-y, repeat-y;
  mask-repeat: no-repeat, repeat-x, repeat-x, repeat-y, repeat-y;
  -webkit-mask-position: 50% 50%, calc(var(--wear-origin) + var(--top-wear, 0px) * var(--wear-offset)) 0%, calc(var(--wear-origin) + var(--bottom-wear, 29px) * var(--wear-offset)) 100%, 0% var(--left-wear, 11px), 100% var(--right-wear, 57px);
  mask-position: 50% 50%, calc(var(--wear-origin) + var(--top-wear, 0px) * var(--wear-offset)) 0%, calc(var(--wear-origin) + var(--bottom-wear, 29px) * var(--wear-offset)) 100%, 0% var(--left-wear, 11px), 100% var(--right-wear, 57px);
  clip-path: polygon(.7px 0, calc(100% - .6px) 0, 100% .6px, 100% calc(100% - var(--right-corner-cut)), calc(100% - .5px) calc(100% - var(--right-corner-cut) + .4px), calc(100% - var(--right-corner-cut)) 100%, var(--left-corner-cut) 100%, .5px calc(100% - .5px), 0 calc(100% - var(--left-corner-cut)), 0 .7px);
}
#museum-app .bound-volume {
  isolation: isolate;
  background: none;
  border-color: transparent;
  box-shadow: calc(4px * var(--book-reflection)) 13px 14px #4d3e3255, calc(9px * var(--book-reflection)) 27px 38px #4d3e3250;
}
#museum-app .bound-volume::after {
  content: '';
  position: absolute;
  inset: -1px;
  z-index: -1;
  pointer-events: none;
  border: 1px solid transparent;
  border-radius: 4px 3px 5px 4px;
  border-image: var(--cover-corners) 22% / 54px / 0 stretch;
  background-color: #622c34;
  background-image:
    linear-gradient(var(--book-angle), #17070c62 0, transparent 12px, #fff5d41a 17px, #00000039 30px, transparent 45px),
    linear-gradient(180deg, #ffebc614, transparent 45%, #25091050),
    var(--cloth-texture);
  background-size: 100% 100%, 100% 100%, 340px 340px;
  box-shadow: inset 1px 2px 2px #dfad9f55, inset -3px -5px 5px #1b090c8c;
}
#museum-app .catalogue-leaf {
  border-radius: var(--paper-radius);
  background: none;
  border-color: transparent;
  box-shadow: calc(-5px * var(--book-reflection)) 0 8px #21110849, calc(2px * var(--book-reflection)) 3px 6px #28170c45;
}
#museum-app .catalogue-leaf::before { z-index: 1; }
#museum-app .catalogue-leaf::after { content: none; }
#museum-app .catalogue-leaf > .leaf-surface {
  position: absolute;
  inset: -1px;
  z-index: 0;
  pointer-events: none;
  --top-wear: 37px;
  --bottom-wear: 91px;
  --left-wear: 129px;
  --right-wear: 211px;
  border: 1px solid transparent;
  border-image: var(--paper-corners) 22% / 82px / 0 stretch;
  background-color: #f0e5cf;
  background-image:
    linear-gradient(var(--book-angle), #755d383b 0, #b9a17810 15px, #fff8e937 25px, transparent 55px),
    linear-gradient(#faf4e565, #faf4e54d),
    var(--paper-texture);
  background-size: 100% 100%, 100% 100%, 980px 980px;
  box-shadow: inset 1px 0 2px #fff7dcca, inset -2px 0 4px #a7834c2b;
}
#museum-app .leaf-surface::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('/museum/assets/paper-grit.svg'), var(--paper-texture);
  background-size: 100% 100%, 710px 1067px;
  background-position: center, 137px -171px;
  opacity: .19;
  mask-image: radial-gradient(ellipse at 46% 48%, transparent 25%, #0008 75%, #000 100%);
  scale: var(--book-reflection) 1;
}
#museum-app .paper-stack::before {
  --top-wear: 113px;
  --bottom-wear: 173px;
  --left-wear: 67px;
  --right-wear: 283px;
  border-color: transparent;
  border-image: var(--paper-corners) 22% / 42px / 0 stretch;
}
#museum-app .paper-stack::after {
  --top-wear: 197px;
  --bottom-wear: 47px;
  --left-wear: 231px;
  --right-wear: 19px;
  border-color: transparent;
  border-image: var(--paper-corners) 22% / 38px / 0 stretch;
}

/* Rounded sheets retain the fine edge masks; wear follows the curved rim. */
#museum-app .leaf-surface,
#museum-app .section-leaf,
#museum-app .paper-stack::before,
#museum-app .paper-stack::after {
  border-radius: var(--paper-radius);
  clip-path: inset(0 round var(--paper-radius));
}
#museum-app .leaf-surface::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background-image: var(--paper-grit-top), var(--paper-grit-bottom), var(--paper-grit-left), var(--paper-grit-right);
  background-size: 803px 18px, 803px 18px, 18px 803px, 18px 803px;
  background-repeat: repeat-x, repeat-x, repeat-y, repeat-y;
  background-position: 37px 0, -89px 100%, 0 -147px, 100% -391px;
  box-shadow: inset 0 0 1.5px #82653780;
  opacity: .8;
}
#museum-app .section-leaf,
#museum-app .paper-stack::before,
#museum-app .paper-stack::after {
  border: 1px solid transparent;
  border-image: var(--paper-corners) 22% / 82px / 0 stretch;
  background-image:
    var(--paper-grit-top), var(--paper-grit-bottom), var(--paper-grit-left), var(--paper-grit-right),
    linear-gradient(var(--book-angle), #81653655, #efdfc228 15px, transparent 26px),
    var(--paper-texture);
  background-size: 803px 18px, 803px 18px, 18px 803px, 18px 803px, 100% 100%, 710px 1067px;
  background-repeat: repeat-x, repeat-x, repeat-y, repeat-y, no-repeat, repeat;
  background-position: 113px 0, -179px 100%, 0 -231px, 100% -57px, center, 139px -173px;
  box-shadow: inset 0 0 1px #70563280, calc(1px * var(--book-reflection)) 1px 2px #59412c55;
}
#museum-app .section-leaf {
  background-position: calc(var(--leaf-depth) * 37px) 0, calc(var(--leaf-depth) * -83px) 100%, 0 calc(var(--leaf-depth) * -113px), 100% calc(var(--leaf-depth) * 73px), center, calc(var(--leaf-depth) * 47px) calc(var(--leaf-depth) * -71px);
}

@media (max-width: 650px) {
  body {
    padding: 0;
    background-color: var(--table-background-color);
    background-image: var(--table-background-image);
    background-size: auto, auto;
    background-blend-mode: normal, multiply;
  }
  #museum-app .museum-stage { max-width: none; margin: 0; padding: 0; }
  #museum-app .bound-volume { border-radius: 0; box-shadow: calc(4px * var(--book-reflection)) 13px 14px #4d3e3255, calc(9px * var(--book-reflection)) 27px 38px #4d3e3250; }
  #museum-app .bound-volume::after { border-radius: 0; }
}

/* Viewport rules share one phone boundary; margins grow without a width reversal. */
@media (width > 650px) {
  body {
    padding-block: clamp(0px, calc((100vw - 650px) * .112), 28px) clamp(0px, calc((100vw - 650px) * .06), 16px);
    padding-inline: clamp(0px, calc((100vw - 650px) * .096), 24px);
  }
  #museum-app .museum-stage {
    padding-block: clamp(0px, calc((100vw - 650px) * .02), 5px) 0;
    padding-inline: clamp(0px, calc((100vw - 650px) * .036), 9px);
  }
}

/* Safari canvas and overscroll use the surrounding background, not bookcloth. */
html { background-color: var(--table-background-color); }
