.book-index-tabs {
  position: absolute;
  z-index: 16;
  display: block;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  scrollbar-width: none;
  overscroll-behavior: contain;
  touch-action: none;
  --index-depth: 66px;
  --index-rest-depth: 26px;
  --index-text: #fff;
  --index-font: 14px;
  --index-weight: 600;
  --index-letter-spacing: 0px;
  --index-line-height: 1.25;
  --index-expanded-depth: 61px;
}

.book-index-tabs[hidden] { display: none !important; }
.book-index-tabs::-webkit-scrollbar { display: none; }
.stage.has-index-tabs #book-shell { transition: none; }

.book-index-tab {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  border: 0;
  padding: 0;
  overflow: hidden;
  background: var(--index-color);
  color: var(--index-text);
  font: var(--index-weight) var(--index-font)/var(--index-line-height) system-ui, sans-serif;
  letter-spacing: var(--index-letter-spacing);
  cursor: pointer;
  user-select: none;
  --index-shadow: inset 0 -1px 0 #0002;
  box-shadow: var(--index-shadow);
}

.book-index-tab[aria-current=page] { --index-shadow: inset 0 0 0 1px #fff5; }
.book-index-tab:focus-visible { outline: 2px solid var(--index-text); outline-offset: -3px; }
.book-index-tab.is-expanded { opacity: 0; }
.book-index-tab .book-index-label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(1px, calc(var(--index-label-length, var(--index-length, 68px)) - 20px));
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.book-index-tabs[data-position=top] .book-index-tab {
  left: var(--index-offset, 0px);
  bottom: 0;
  width: var(--index-visible-length, var(--index-length, 68px));
  height: var(--index-rest-depth);
  border-radius: 3px 3px 0 0;
}
.book-index-tabs[data-position=left] .book-index-tab,
.book-index-tabs[data-position=right] .book-index-tab {
  top: var(--index-offset, 0px);
  width: var(--index-rest-depth);
  height: var(--index-visible-length, var(--index-length, 68px));
  border-radius: 0 3px 3px 0;
}
.book-index-tabs[data-position=right] .book-index-tab { left: 0; }
.book-index-tabs[data-position=left] .book-index-tab { right: 0; border-radius: 3px 0 0 3px; }
.book-index-tabs[data-position=top] .book-index-label { left: calc(var(--index-label-length, var(--index-length, 68px)) / 2); }
.book-index-tabs[data-position=right] .book-index-label { top: calc(var(--index-label-length, var(--index-length, 68px)) / 2); transform: translate(-50%, -50%) rotate(90deg); }
.book-index-tabs[data-position=left] .book-index-label { top: calc(var(--index-label-length, var(--index-length, 68px)) / 2); transform: translate(-50%, -50%) rotate(-90deg); }
:is(.book-index-tab,.book-index-body)[data-multiline=true]::after {
  content: '⋯';
  position: absolute;
  bottom: 1px;
  right: 3px;
  font: 600 11px/1 system-ui;
  pointer-events: none;
}
.book-index-tabs[data-position=top] :is(.book-index-tab,.book-index-body)[data-multiline=true]::after { right: auto; left: max(0px, calc(var(--index-label-length) - 8px)); }
.book-index-tabs[data-position=left] :is(.book-index-tab,.book-index-body)[data-multiline=true]::after,
.book-index-tabs[data-position=right] :is(.book-index-tab,.book-index-body)[data-multiline=true]::after { bottom: auto; top: max(0px, calc(var(--index-label-length) - 8px)); }
.book-index-tab.has-index-body::after { display: none; }

/* The clipped face slides out from the book edge without moving adjacent tabs. */
.book-index-hover {
  position: fixed;
  z-index: 160;
  box-sizing: border-box;
  color: var(--index-text);
  font: var(--index-weight, 600) var(--index-font, 14px)/var(--index-line-height, 1.25) system-ui, sans-serif;
  letter-spacing: var(--index-letter-spacing, 0px);
  text-align: center;
  user-select: none;
  pointer-events: none;
}
.book-index-slide { position: absolute; inset: 0; overflow: hidden; border-radius: 0 3px 3px 0; }
.book-index-face {
  position: absolute;
  inset: 0;
  background: var(--index-color);
  box-shadow: inset 0 -1px 0 #0002;
  cursor: pointer;
  pointer-events: auto;
  touch-action: auto;
  transform: translateX(calc(-1 * var(--index-travel)));
  transition: transform .22s ease-out;
}
.book-index-hover[data-position=left] .book-index-slide { border-radius: 3px 0 0 3px; }
.book-index-hover[data-position=left] .book-index-face { transform: translateX(var(--index-travel)); }
.book-index-hover[data-position=top] .book-index-slide { border-radius: 3px 3px 0 0; }
.book-index-hover[data-position=top] .book-index-face { transform: translateY(var(--index-travel)); }
.book-index-hover.is-open .book-index-face { transform: translate(0, 0); }
.book-index-hover.is-preparing .book-index-face { transition: none; }
.book-index-hover.is-closing .book-index-face { pointer-events: none; }
.book-index-hover.has-keyboard-focus .book-index-face { outline: 2px solid var(--index-text); outline-offset: -3px; }
.book-index-hover .book-index-label {
  position: absolute;
  top: 50%;
  right: var(--index-label-inset);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transform: translate(50%, -50%) rotate(90deg);
  pointer-events: none;
}
.book-index-hover[data-position=left] .book-index-label {
  right: auto;
  left: var(--index-label-inset);
  transform: translate(-50%, -50%) rotate(-90deg);
}
.book-index-hover[data-position=top] .book-index-label {
  right: auto;
  left: 50%;
  top: var(--index-label-inset);
  transform: translate(-50%, -50%);
}
.book-index-hover.has-overflow .book-index-label {
  overflow-y: auto;
  scrollbar-width: thin;
  pointer-events: auto;
  touch-action: auto;
}
.book-index-page {
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 3px 7px;
  background: #222;
  color: #fff;
  font: 12px/1.2 system-ui, sans-serif;
  letter-spacing: normal;
  transform: translate(20%, 0);
  opacity: 0;
  transition: opacity .12s ease;
}
.book-index-hover[data-position=left] .book-index-page { right: auto; left: 0; transform: translate(-20%, 0); }
.book-index-hover[data-position=top] .book-index-page { bottom: auto; top: 0; transform: translate(0, -40%); }
.book-index-hover.is-open .book-index-page { opacity: 1; transition-delay: .16s; }

/* The hover face transform remains reserved for the book-edge slide. */
.book-index-label { z-index: 1; }
.book-index-text { display: block; }
.book-index-tab .book-index-text { overflow: hidden; text-overflow: ellipsis; }
:is(.book-index-tab,.book-index-face)[data-index-animation]::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
}
[data-index-animation=pulse]::before { background: #fff; animation: index-pulse 3s ease-in-out infinite; }
[data-index-animation=glow]::before { animation: index-glow 3.2s ease-in-out infinite; }
[data-index-animation=shine]::before {
  background: linear-gradient(115deg,transparent 35%,#fff9 50%,transparent 65%) -100% 0 / 300% 100% no-repeat;
  animation: index-shine 3.6s ease-in-out infinite;
}
[data-index-animation=wave]::before {
  background: linear-gradient(100deg,transparent,#ffe4a5aa,transparent,#d7e8ff99,transparent) 0 0 / 300% 100%;
  animation: index-wave 4s ease-in-out infinite;
}
[data-index-animation=ripple]::before {
  background: radial-gradient(ellipse,transparent 30%,#fff9 33%,#fff6 38%,transparent 43%);
  animation: index-ripple 3.6s ease-out infinite;
}
[data-index-animation=border]::before {
  background: linear-gradient(90deg,transparent,#fff4a8,transparent) 0 0 / 40% 2px no-repeat,
    linear-gradient(180deg,transparent,#fff4a8,transparent) 100% 0 / 2px 40% no-repeat,
    linear-gradient(270deg,transparent,#fff4a8,transparent) 100% 100% / 40% 2px no-repeat,
    linear-gradient(0deg,transparent,#fff4a8,transparent) 0 100% / 2px 40% no-repeat;
  animation: index-border 3s linear infinite;
}
[data-index-animation=sparkle]::before {
  background: radial-gradient(circle at 16% 25%,#fff 0 1.5px,transparent 3px),
    radial-gradient(circle at 52% 70%,#fff8c4 0 2px,transparent 4px),
    radial-gradient(circle at 84% 30%,#fff 0 1px,transparent 3px);
  animation: index-sparkle 3.4s ease-in-out infinite;
}
[data-index-animation=breathe] .book-index-text { animation: index-breathe 3s ease-in-out infinite; }
[data-index-animation=sway] .book-index-text { animation: index-sway 3.2s ease-in-out infinite; }
[data-index-animation=bounce] .book-index-text { animation: index-bounce 3s ease-in-out infinite; }
.book-index-body {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  --index-bounce-distance: max(0px, min(8px, calc(var(--index-depth) - var(--index-rest-depth) - 1px)));
  --index-bounce-top: 0px;
  --index-bounce-right: 0px;
  --index-bounce-left: 0px;
}
.book-index-tabs[data-position=right] .book-index-body { --index-bounce-right: calc(-1 * var(--index-bounce-distance)); }
.book-index-tabs[data-position=left] .book-index-body { --index-bounce-left: calc(-1 * var(--index-bounce-distance)); }
.book-index-tabs[data-position=top] .book-index-body { --index-bounce-top: calc(-1 * var(--index-bounce-distance)); }
/* Stretch only the outer edge; the background stays attached to the book.
   Anchor lettering to that outer edge so it moves without being stretched. */
.book-index-tabs[data-position=right] .book-index-body .book-index-label { left: calc(100% - var(--index-rest-depth) / 2); }
.book-index-tabs[data-position=left] .book-index-body .book-index-label { left: calc(var(--index-rest-depth) / 2); }
.book-index-tabs[data-position=top] .book-index-body .book-index-label { top: calc(var(--index-rest-depth) / 2); }
.book-index-tabs[data-position=left] .book-index-body[data-multiline=true]::after { left: 3px; right: auto; }
.book-index-tabs[data-position=top] .book-index-body[data-multiline=true]::after { top: calc(var(--index-rest-depth) - 12px); bottom: auto; }
.book-index-tab[data-index-animation=tab-bounce] { overflow: visible; background: transparent; box-shadow: none; }
.book-index-tab[data-index-animation=tab-bounce] > .book-index-body {
  background: var(--index-color);
  box-shadow: var(--index-shadow);
  animation: index-tab-bounce 3s ease-in-out infinite;
}
.book-index-tab.is-expanded > .book-index-body { animation-play-state: paused; }
@keyframes index-tab-bounce {
  0%,24%,40%,100% { top: 0; right: 0; left: 0; }
  12% { top: var(--index-bounce-top); right: var(--index-bounce-right); left: var(--index-bounce-left); }
  32% { top: calc(var(--index-bounce-top) * .45); right: calc(var(--index-bounce-right) * .45); left: calc(var(--index-bounce-left) * .45); }
}
@keyframes index-pulse { 0%,100% { opacity: 0; } 50% { opacity: .32; } }
@keyframes index-glow { 0%,100% { opacity: .25; box-shadow: inset 0 0 0 1px #fff6; } 50% { opacity: 1; box-shadow: inset 0 0 0 2px #fff4ad, inset 0 0 12px #fff8; } }
@keyframes index-shine { 0%,15% { opacity: 0; background-position: 100% 0; } 25%,60% { opacity: .9; } 75%,100% { opacity: 0; background-position: 0 0; } }
@keyframes index-wave { 0%,100% { opacity: .25; background-position: 0 0; } 50% { opacity: .8; background-position: 100% 0; } }
@keyframes index-ripple { 0%,15% { opacity: 0; transform: scale(.15); } 25% { opacity: .85; } 80%,100% { opacity: 0; transform: scale(2.5); } }
@keyframes index-border { 0% { opacity: 1; background-position: 0 0,100% 0,100% 100%,0 100%; } 100% { opacity: 1; background-position: 100% 0,100% 100%,0 100%,0 0; } }
@keyframes index-sparkle { 0%,100% { opacity: .1; } 50% { opacity: 1; } }
@keyframes index-breathe { 0%,100% { transform: scale(.96); } 50% { transform: scale(1.04); } }
@keyframes index-sway { 0%,40%,100% { transform: translateX(0); } 10%,30% { transform: translateX(-2px); } 20% { transform: translateX(2px); } }
@keyframes index-bounce { 0%,40%,100% { transform: translateY(0); } 12% { transform: translateY(-3px); } 24% { transform: translateY(0); } 32% { transform: translateY(-1.5px); } }

@media (prefers-reduced-motion: reduce) {
  .book-index-face, .book-index-page { transition: none; }
  :is(.book-index-tab,.book-index-face)[data-index-animation]::before { animation: none; transform: none; background: none; opacity: 1; box-shadow: inset 0 0 0 2px #fff4ad; }
  [data-index-animation] .book-index-text { animation: none; transform: none; }
  .book-index-tab[data-index-animation=tab-bounce] > .book-index-body { animation: none; transform: none; box-shadow: inset 0 0 0 2px #fff4ad; }
}

/* Phones: compact index strip above the book (the reader reserves its height). */
.mobile-index-strip { position: absolute; z-index: 16; top: 6px; left: 0; right: 0; display: flex; gap: 6px; height: 32px; padding: 0 10px; box-sizing: border-box; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; touch-action: pan-x; -webkit-overflow-scrolling: touch; }
.mobile-index-strip[hidden] { display: none !important; }
.mobile-index-strip::-webkit-scrollbar { display: none; }
.mobile-index-tab { flex: none; max-width: 46vw; height: 30px; margin: 1px 0; padding: 0 12px; border: 0; border-radius: 15px; background: var(--index-color, #3963a5); color: var(--index-text, #fff); font: 600 13px/30px system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .78; cursor: pointer; box-shadow: 0 1px 3px #0003; }
.mobile-index-tab[aria-current=page] { opacity: 1; box-shadow: inset 0 0 0 2px #fffc, 0 1px 3px #0003; }
.mobile-index-tab:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
@media (min-width: 761px) { .mobile-index-strip { display: none !important; } }
