/* ממלכת הכסף - book-flip component (vanilla, no libs)
   Neutral styling: inherits text color, works on dark navy and on light sections.
   Brand: purple #6545A1, lime #B2EF03. */

.bookflip {
  --bf-purple: #6545A1;
  --bf-lime: #B2EF03;
  --bf-paper: #fbfaf6;
  --bf-edge: #e4dfd2;
  --bf-ink: currentColor;
  --bf-board: #533d9f;          /* set per book from JS */
  --bf-endpaper: #6a52b6;       /* set per book from JS */
  position: relative;
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  direction: rtl;
  color: inherit;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- level toggle ---------- */
.bf-toggle {
  display: flex;
  justify-content: center;
  gap: 6px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto 22px;
  padding: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 16%, transparent);
}
.bf-toggle button {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  padding: 10px 18px;
  border-radius: 999px;
  color: inherit;
  background: transparent;
  opacity: .78;
  transition: background-color .25s, color .25s, opacity .25s, box-shadow .25s;
  white-space: nowrap;
}
.bf-toggle button:hover { opacity: 1; }
.bf-toggle button[aria-selected="true"] {
  background: var(--bf-purple);
  color: #fff;
  opacity: 1;
  box-shadow: 0 0 0 2px var(--bf-lime) inset, 0 6px 18px rgba(101, 69, 161, .35);
}
.bf-toggle button:focus-visible,
.bf-nav button:focus-visible,
.bf-viewport:focus-visible {
  outline: 3px solid var(--bf-lime);
  outline-offset: 3px;
}

/* ---------- stage ---------- */
.bf-viewport {
  position: relative;
  margin-inline: auto;
  touch-action: pan-y;
  cursor: pointer;
  outline: none;
}
.bf-clip { position: absolute; inset: 0; }
.bookflip.is-single .bf-clip {
  /* single-page view: hide whatever turns past the spine (right edge) */
  clip-path: inset(-45% 0 -45% -45%);
}
.bf-book {
  position: absolute;
  top: 0;
  left: 0;
  direction: ltr;               /* geometry is computed in LTR space */
  will-change: transform;
}
.bf-fade { transition: opacity .28s ease; }
.bookflip.is-swapping .bf-fade { opacity: 0; }

/* floor shadow */
.bf-floor {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: -5%;
  height: 10%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.42) 0%, rgba(0,0,0,.18) 42%, rgba(0,0,0,0) 72%);
  filter: blur(6px);
  pointer-events: none;
}

/* covers' boards (back cover under everything) */
.bf-board {
  position: absolute;
  background: var(--bf-board);
  border-radius: 3px 6px 6px 3px;
  box-shadow: 0 18px 40px -12px rgba(0,0,0,.55), 0 4px 10px rgba(0,0,0,.25);
}
.bf-board::after {                    /* endpaper shown when the back board is exposed */
  content: "";
  position: absolute;
  inset: var(--bf-m, 10px) 0 var(--bf-m, 10px) var(--bf-m, 10px);
  background: var(--bf-endpaper);
  border-radius: 2px;
  box-shadow: inset -14px 0 22px -12px rgba(0,0,0,.45);
}
.bookflip.is-single .bf-board { border-radius: 6px 3px 3px 6px; }

/* stacks of paper (thickness drawn by box-shadow from JS) */
.bf-stack {
  position: absolute;
  background: var(--bf-paper);
  border-radius: 1px;
  transition: opacity .2s;
}

/* cast shadows on the pages beneath a turning leaf */
.bf-cast {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  z-index: 900;
}
.bf-cast-l { background: linear-gradient(to left, rgba(0,0,0,.55), rgba(0,0,0,.08) 70%, rgba(0,0,0,0)); }
.bf-cast-r { background: linear-gradient(to right, rgba(0,0,0,.55), rgba(0,0,0,.08) 70%, rgba(0,0,0,0)); }

/* ---------- leaves ---------- */
.bf-leaf {
  position: absolute;
  transform-origin: 100% 50%;          /* the spine */
  transform-style: preserve-3d;
}
.bf-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bf-paper);
}
.bf-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}
.bf-back { transform: rotateY(180deg); }
.bf-face.is-blank { background: var(--bf-paper); }
.bf-face.is-endpaper { background: var(--bf-endpaper); }

/* gutter shading: front faces sit on the left page (spine at their right edge),
   back faces land on the right page (spine at their left edge) */
.bf-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.bf-front::after {
  background:
    linear-gradient(to left, rgba(0,0,0,.30) 0%, rgba(0,0,0,.10) 3.5%, rgba(255,255,255,.10) 6%, rgba(0,0,0,0) 12%),
    linear-gradient(to right, rgba(0,0,0,.05), rgba(0,0,0,0) 4%);
}
.bf-back::after {
  background:
    linear-gradient(to right, rgba(0,0,0,.30) 0%, rgba(0,0,0,.10) 3.5%, rgba(255,255,255,.10) 6%, rgba(0,0,0,0) 12%),
    linear-gradient(to left, rgba(0,0,0,.05), rgba(0,0,0,0) 4%);
}
/* dynamic shade while turning (opacity set from JS) */
.bf-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
}
.bf-front .bf-shade { background: linear-gradient(to left, rgba(0,0,0,.5), rgba(0,0,0,.12) 55%, rgba(255,255,255,.08)); }
.bf-back .bf-shade  { background: linear-gradient(to right, rgba(0,0,0,.5), rgba(0,0,0,.12) 55%, rgba(255,255,255,.08)); }

/* the cover */
.bf-leaf.is-cover .bf-face { border-radius: 3px 6px 6px 3px; }
.bf-leaf.is-cover .bf-front { border-radius: 6px 3px 3px 6px; }
.bf-leaf.is-cover .bf-front::after {
  background:
    linear-gradient(to left, rgba(0,0,0,.38) 0%, rgba(255,255,255,.28) 1.2%, rgba(0,0,0,.18) 2.6%, rgba(255,255,255,.10) 4.2%, rgba(0,0,0,0) 7%),
    linear-gradient(115deg, rgba(255,255,255,0) 30%, rgba(255,255,255,.16) 45%, rgba(255,255,255,0) 60%),
    linear-gradient(to bottom, rgba(255,255,255,.06), rgba(0,0,0,.08));
}
.bf-leaf.is-cover .bf-back::after {
  inset: var(--bf-m, 10px) var(--bf-m, 10px) var(--bf-m, 10px) 0;
  background: var(--bf-endpaper);
  box-shadow: inset 14px 0 22px -12px rgba(0,0,0,.45);
  border-radius: 2px;
}
.bf-leaf.is-cover .bf-back { background: var(--bf-board); }

/* ---------- nav ---------- */
.bf-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 26px;
}
.bf-nav button {
  appearance: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
  background: color-mix(in srgb, currentColor 6%, transparent);
  color: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background-color .2s, border-color .2s, opacity .2s;
}
.bf-nav button:hover { background: var(--bf-purple); border-color: var(--bf-purple); color: #fff; }
.bf-nav button:disabled { opacity: .35; cursor: default; background: transparent; color: inherit; border-color: color-mix(in srgb, currentColor 25%, transparent); }
.bf-nav svg { width: 20px; height: 20px; }
.bf-status {
  min-width: 140px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  opacity: .8;
  font-variant-numeric: tabular-nums;
}
.bf-hint {
  text-align: center;
  font-size: 13px;
  opacity: .6;
  margin-top: 8px;
}

@media (max-width: 420px) {
  .bf-toggle button { font-size: 14px; padding: 9px 12px; }
}

/* reduced motion: no fades */
@media (prefers-reduced-motion: reduce) {
  .bf-fade, .bf-toggle button { transition: none; }
}
