/* ==========================================================================
   book3d.css — the book pulled off the shelf (3D dialog + mobile sheet),
   the generated front cover, the catalogue card and the static open book
   on book.php (.spread).
   Geometry of the 3D book (px custom properties set by book3d.js):
     --W cover width, --H height, --T thickness.  Bound on the RIGHT.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Dialog shell
   -------------------------------------------------------------------------- */
.bk {
  position: fixed;
  inset: 0;
  z-index: 100;
  --W: 380px;
  --H: 540px;
  --T: 60px;
}
.bk__backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 70% at 50% 48%, rgba(20, 16, 40, .64), rgba(6, 5, 18, .9));
  opacity: 0;
  transition: opacity .45s ease;
}
.bk.is-shown .bk__backdrop { opacity: 1; }
.bk__stage { position: absolute; inset: 0; pointer-events: none; }
.bk__close {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  pointer-events: auto;
  background: rgba(255, 252, 246, .95);
  opacity: 0;
  transition: opacity .3s ease .2s, transform .2s var(--ease);
}
.bk.is-shown .bk__close { opacity: 1; }

.bk__floor {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--H) / 2 - 12px);
  width: calc(var(--W) * 2.2);
  height: 44px;
  margin-left: calc(var(--W) * -1.1);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
  opacity: 0;
  transform: scaleX(.45);
  transition: opacity .5s ease, transform .9s var(--ease-io);
}
.bk[data-stage="fly"] .bk__floor { opacity: .9; }
.bk[data-stage="open"] .bk__floor { opacity: 1; transform: none; }
.bk[data-stage="close"] .bk__floor { opacity: .9; transform: scaleX(.45); }
.bk[data-stage="back"] .bk__floor { opacity: 0; transform: scaleX(.45); }

/* --------------------------------------------------------------------------
   3D mode
   -------------------------------------------------------------------------- */
.bk[data-mode="3d"] .bk__book {
  position: absolute;
  left: calc(50% - var(--W) / 2);
  top: calc(50% - var(--H) / 2);
  width: var(--W);
  height: var(--H);
  transform-style: preserve-3d;
  pointer-events: auto;
  will-change: transform;
}
.bk[data-mode="3d"] .bk__spine {
  /* spine face: centred on the right edge, perpendicular to the cover */
  position: absolute;
  top: 0;
  left: calc(var(--W) - var(--T) / 2);
  width: var(--T);
  height: var(--H);
  overflow: hidden;
  transform: rotateY(90deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bk, #5C5446);
}
.bk__spine > .spine {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition: none;
  pointer-events: none;
}
.bk[data-mode="3d"] .bk__board {
  /* back board seen around the first page when the book lies open */
  position: absolute;
  inset: 0;
  border-radius: 6px 2px 2px 6px;
  transform: translateZ(calc(var(--T) / 2 - 4px));
  background: var(--bk, #5C5446);
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .25), rgba(255, 255, 255, .05) 30%, rgba(0, 0, 0, .15));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3);
}
.bk[data-mode="3d"] .bk__cover {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 100% 50%;
}
.bk[data-mode="3d"] .bk__cover-front,
.bk[data-mode="3d"] .bk__page--card {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.bk[data-mode="3d"] .bk__page--card { transform: rotateY(180deg); }
.bk[data-mode="3d"] .bk__page--loc {
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 9px;
  right: 0;
  transform: translateZ(calc(var(--T) / 2 - 2px));
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* pages ---------------------------------------------------------------------- */
.bk__page {
  display: flex;
  flex-direction: column;
  color: var(--ink);
  text-align: start;
}
.bk__page--card {
  /* inside of the cover: board with a pasted-down card */
  padding: 7px 9px 7px 0;
  border-radius: 2px 6px 6px 2px;
  background: var(--bk, #5C5446);
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .3), rgba(0, 0, 0, .05) 12%, rgba(255, 255, 255, .04) 70%, rgba(0, 0, 0, .2));
}
.bk__page--loc {
  overflow: auto;
  padding: 22px 22px 18px 26px;
  border-radius: 4px 0 0 4px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0) 85%, rgba(60, 40, 10, .16)),
    radial-gradient(ellipse at 30% 20%, #FFFDF8, #FBF4E4 70%, #F3E8D0);
  box-shadow:
    -1px 1px 0 #E9DEC5, -2px 2px 0 #D8CAA9, -3px 3px 0 #EDE3CC, -4px 4px 0 #D3C4A2, -5px 5px 0 #E6DAC0;
  scrollbar-width: thin;
}
.bk__page--loc .location { flex: 1; }
.bk__actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.bk__actions .btn { width: 100%; }
.bk__actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bk__actions-row .btn { padding-inline: 8px; }

/* --------------------------------------------------------------------------
   Generated front cover (.cover) — used by the dialog and the book page
   -------------------------------------------------------------------------- */
.cover {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16% 15% 18% 13%;
  overflow: hidden;
  text-align: center;
  color: var(--gold-ink);
  border-radius: 6px 2px 2px 6px;
  background-color: var(--bk, #5C5446);
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, .18), rgba(255, 255, 255, .06) 35%, rgba(0, 0, 0, .06) 75%, rgba(0, 0, 0, .35) 94%, rgba(0, 0, 0, .15)),
    radial-gradient(ellipse at 40% 30%, rgba(255, 255, 255, .10), transparent 60%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35), inset 0 0 30px rgba(0, 0, 0, .25);
}
.cover[data-binding="leather"], [data-binding="leather"] > .cover,
[data-binding="leather"] .cover {
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, .2), rgba(255, 255, 255, .06) 35%, rgba(0, 0, 0, .06) 75%, rgba(0, 0, 0, .38) 94%, rgba(0, 0, 0, .15)),
    radial-gradient(rgba(0, 0, 0, .10) 1px, transparent 1.3px);
  background-size: auto, 5px 5px;
}
[data-binding="cello"] .cover {
  background-image:
    linear-gradient(115deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, .22) 42%, rgba(255, 255, 255, 0) 55%),
    linear-gradient(90deg, rgba(0, 0, 0, .15), rgba(0, 0, 0, .05) 70%, rgba(0, 0, 0, .35) 94%, rgba(0, 0, 0, .15));
}
.cover::after {
  /* hinge groove next to the spine (right) */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 6%;
  width: 3px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .35), rgba(255, 255, 255, .08));
}
.cover__frame {
  position: absolute;
  inset: 6% 10% 6% 5%;
  border: 1.5px solid rgba(232, 207, 143, .75);
  outline: 1px solid rgba(232, 207, 143, .4);
  outline-offset: 5px;
  border-radius: 3px;
  pointer-events: none;
}
.cover__frame::before, .cover__frame::after {
  /* corner fleurons */
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1.5px solid rgba(232, 207, 143, .7);
  transform: rotate(45deg);
  left: 50%;
  margin-left: -7px;
}
.cover__frame::before { top: -8px; background: var(--bk, #5C5446); }
.cover__frame::after { bottom: -8px; background: var(--bk, #5C5446); }
.cover__orn {
  position: relative;
  flex: none;
  width: calc(var(--cw, var(--W)) * .1);
  height: calc(var(--cw, var(--W)) * .1);
  margin-bottom: 8%;
}
.cover__orn::before, .cover__orn::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid currentColor;
}
.cover__orn::after { transform: rotate(45deg); }
.cover__title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: calc(var(--cw, var(--W)) * .082);
  line-height: 1.45;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .55);
  overflow-wrap: anywhere;
}
.cover__rule {
  flex: none;
  width: 36%;
  height: 7px;
  margin: 6% 0 4%;
  background:
    linear-gradient(currentColor, currentColor) center / 100% 1px no-repeat,
    radial-gradient(circle, currentColor 2.5px, transparent 3px) center / 7px 7px no-repeat;
  opacity: .8;
}
.cover__author {
  font-family: var(--font-title);
  font-size: calc(var(--cw, var(--W)) * .05);
  line-height: 1.5;
  opacity: .92;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.cover__vol {
  margin-top: 5%;
  padding: 1px 12px;
  border: 1px solid rgba(232, 207, 143, .7);
  border-radius: 2px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: calc(var(--cw, var(--W)) * .04);
}
.cover__foot {
  position: absolute;
  left: 8%;
  right: 12%;
  bottom: 9%;
  font-size: calc(var(--cw, var(--W)) * .032);
  letter-spacing: .02em;
  opacity: .8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cover__band {
  /* magazines: coloured band with the issue number */
  position: absolute;
  top: 13%;
  left: 0;
  right: 0;
  padding: 1.5% 8%;
  background: #E8CF8F;
  background: color-mix(in srgb, var(--bk, #5C5446) 25%, #F1E3BE);
  color: #22190B;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: calc(var(--cw, var(--W)) * .04);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .3);
}

/* --------------------------------------------------------------------------
   Catalogue card («بطاقة الفهرسة»)
   -------------------------------------------------------------------------- */
.ccard {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 30px 20px;
  border-radius: 1px 3px 3px 1px;
  background:
    linear-gradient(90deg, rgba(60, 40, 10, .18), rgba(0, 0, 0, 0) 7%),
    radial-gradient(ellipse at 70% 10%, #FFFEFA, #FCF6E8 65%, #F4EAD3);
  scrollbar-width: thin;
}
.ccard__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 2px solid rgba(170, 45, 40, .55);
}
.ccard__kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: #8A3A33;
}
.ccard__reg { font-size: .8125rem; color: var(--muted); }
.ccard__reg b {
  font-size: 1.2rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.ccard__label { margin: 0; font-size: .75rem; font-weight: 600; color: var(--muted); }
.ccard__title {
  margin: 0 0 10px;
  font-size: 1.45rem;
  line-height: 1.45;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.ccard__title:focus { outline: none; }
.ccard__vol {
  display: inline-block;
  margin-inline-start: 6px;
  padding: 0 8px;
  border: 1px solid var(--gold-2);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 600;
  color: var(--gold-text);
  vertical-align: .25em;
  line-height: 1.6;
}
.ccard__vol:empty { display: none; }
.ccard__rows {
  --lh: 28px;
  display: grid;
  font-size: .9063rem;
  line-height: var(--lh);
  background:
    linear-gradient(90deg, transparent calc(100% - 7.6em), rgba(170, 45, 40, .35) calc(100% - 7.6em) calc(100% - 7.6em + 1px), transparent calc(100% - 7.6em + 1px)),
    repeating-linear-gradient(180deg, transparent 0 calc(var(--lh) - 1px), rgba(14, 5, 131, .14) calc(var(--lh) - 1px) var(--lh));
}
.ccard__row { display: grid; grid-template-columns: 7.6em minmax(0, 1fr); }
.ccard__row dt { padding-inline-end: 10px; color: var(--muted); font-size: .8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard__row dd { padding-inline-start: 10px; color: var(--ink); overflow-wrap: anywhere; }
.ccard__row dd a { color: var(--primary); }
.ccard__hole {
  position: absolute;
  bottom: 10px;
  left: 50%;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, rgba(0, 0, 0, .35), rgba(0, 0, 0, .12));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .45), 0 1px 0 rgba(255, 255, 255, .8);
}

/* --------------------------------------------------------------------------
   Sheet mode (small screens, reduced motion)
   -------------------------------------------------------------------------- */
.bk[data-mode="sheet"] .bk__book {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 68px);
  max-height: calc(100dvh - 68px);
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom, 0);
  border-radius: 20px 20px 0 0;
  background: var(--paper);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .35);
  pointer-events: auto;
}
.bk[data-mode="sheet"] .bk__book::before {
  /* coloured top band + grab handle */
  content: "";
  flex: none;
  height: 22px;
  border-radius: 20px 20px 0 0;
  background:
    linear-gradient(rgba(255, 255, 255, .55), rgba(255, 255, 255, .55)) center 9px / 44px 4px no-repeat,
    var(--bk, var(--primary));
}
.bk[data-mode="sheet"] .bk__spine,
.bk[data-mode="sheet"] .bk__board,
.bk[data-mode="sheet"] .bk__cover-front { display: none; }
.bk[data-mode="sheet"] .bk__cover { display: contents; }
.bk[data-mode="sheet"] .bk__page { position: static; transform: none; }
.bk[data-mode="sheet"] .bk__page--card { padding: 0; background: none; border-radius: 0; }
.bk[data-mode="sheet"] .ccard { overflow: visible; background: var(--card); padding: 16px 18px 30px; border-bottom: 1px solid var(--line); }
.bk[data-mode="sheet"] .bk__page--loc { overflow: visible; padding: 18px; box-shadow: none; background: none; }
.bk[data-mode="sheet"] .bk__close { top: 12px; left: 12px; }
.bk[data-mode="sheet"] .bk__floor { display: none; }

@media (min-width: 760px) {
  /* desktop with reduced motion: a centred card with the two pages side by side */
  .bk[data-mode="sheet"] .bk__book {
    left: 50%;
    top: 50%;
    bottom: auto;
    right: auto;
    width: min(880px, 92vw);
    max-height: 88vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-radius: 16px;
    transform: translate(-50%, -50%);
  }
  .bk[data-mode="sheet"] .bk__book::before { grid-column: 1 / -1; border-radius: 16px 16px 0 0; }
  .bk[data-mode="sheet"] .ccard { border-bottom: 0; border-inline-end: 1px solid var(--line); height: 100%; }
  .bk[data-mode="sheet"] .bk__close { top: 18px; bottom: auto; left: 18px; }
}

/* --------------------------------------------------------------------------
   Static open book on book.php
   -------------------------------------------------------------------------- */
.spread {
  --cw: clamp(330px, 44vw, 470px);
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  max-width: 1000px;
  margin-inline: auto;
}
.spread__cover, .spread__left {
  position: relative;
  padding: 8px;
  border-radius: 8px;
  background-color: var(--bk, #5C5446);
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .25), rgba(255, 255, 255, .05) 30%, rgba(0, 0, 0, .18));
  box-shadow: 0 18px 40px -18px rgba(30, 20, 8, .6);
}
.spread__card { height: 100%; display: flex; flex-direction: column; }
.spread__card .ccard { overflow: visible; padding: 22px 22px 36px; }
.spread__card .ccard__title { font-size: var(--fs-2xl); }
.spread__left > .page {
  height: 100%;
  padding: 24px 22px 20px;
  border-radius: 3px;
  background: radial-gradient(ellipse at 30% 20%, #FFFDF8, #FBF4E4 70%, #F3E8D0);
}
.spread__front { display: none; }
.spread__cover { z-index: 2; }
.spread__left { z-index: 1; margin-top: 14px; }

@media (min-width: 760px) {
  .spread {
    grid-template-columns: 1fr 1fr;
    perspective: 2400px;
    padding: 0;
  }
  .spread__cover {
    padding: 10px 10px 10px 0;
    border-radius: 2px 10px 10px 2px;
    transform-origin: 0 50%;
    transform-style: preserve-3d;
    animation: spread-open 1.25s .35s var(--ease-io) backwards;
  }
  .spread__left {
    margin-top: 0;
    padding: 10px 0 10px 10px;
    border-radius: 10px 2px 2px 10px;
  }
  .spread__card, .spread__front { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
  .spread__card .ccard {
    background:
      linear-gradient(90deg, rgba(60, 40, 10, .22), rgba(0, 0, 0, 0) 9%),
      radial-gradient(ellipse at 70% 10%, #FFFEFA, #FCF6E8 65%, #F4EAD3);
  }
  .spread__left > .page {
    background:
      linear-gradient(90deg, rgba(0, 0, 0, 0) 88%, rgba(60, 40, 10, .2)),
      radial-gradient(ellipse at 30% 20%, #FFFDF8, #FBF4E4 70%, #F3E8D0);
  }
  .spread__front {
    display: flex;
    position: absolute;
    inset: 0;
    transform: rotateY(180deg);
    border-radius: 6px 2px 2px 6px;
  }
  .spread::after {
    /* spine shadow in the gutter */
    content: "";
    position: absolute;
    z-index: 3;
    top: 10px;
    bottom: 10px;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    background: rgba(40, 25, 10, .25);
    pointer-events: none;
  }
}
