/* ============ GLOSSÁRIO — 3D Book Component ============ */
/* All styles scoped to .book-glossary to avoid conflicts  */

.book-glossary {
  position: relative;
  height: 100dvh;
  min-height: 700px;
  overflow: hidden;
  padding: 0 !important;
  background: #02040a;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Neural particle canvas */
.bk-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  pointer-events: none;
}

/* Holographic grid overlay */
.bk-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image:
    linear-gradient(rgba(0,229,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,229,255,.04) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}

/* HUD — top bar */
.bk-hud {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 24px;
  white-space: nowrap;
}

.bk-hud-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: .65rem;
  letter-spacing: .15em;
  color: rgba(0,229,255,.5);
  text-transform: uppercase;
}

.bk-hud-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .05em;
}

.bk-hud-title span {
  color: var(--a2);
}

.bk-page-counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: .65rem;
  color: rgba(0,229,255,.6);
  background: rgba(0,229,255,.07);
  border: 1px solid rgba(0,229,255,.15);
  border-radius: 4px;
  padding: 2px 8px;
}

/* Book stage — perspective container */
.bk-stage {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  perspective: 2500px;
  perspective-origin: center center;
}

/* Book outer wrapper — full spread width */
.bk-book {
  position: relative;
  width: 720px;
  height: 480px;
  transform-style: preserve-3d;
  transform: rotateX(4deg) rotateY(0deg);
  transition: transform .6s cubic-bezier(.23,1,.32,1);
  cursor: pointer;
  user-select: none;
}

@media (max-width: 800px) {
  .bk-book { width: 90vw; height: 60vw; min-height: 320px; }
}
@media (max-width: 480px) {
  .bk-book { width: 95vw; height: 65vw; min-height: 280px; }
}

/*
 * Leaves live in the RIGHT HALF of the spread.
 * transform-origin: left center = the book spine (center of spread).
 * When flipped -180deg, the back face appears in the LEFT HALF.
 */
.bk-leaf {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  transform-style: preserve-3d;
  transform-origin: left center;
  transition: transform .9s cubic-bezier(.645,.045,.355,1);
}

.bk-leaf-cover {
  left: 0;
  right: 0;
  width: 100%;
  transform-origin: 50% center;
}

.bk-leaf.bk-flipped {
  transform: rotateY(-180deg);
}

/* Each face of a leaf */
.bk-front,
.bk-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 0 12px 12px 0;
  overflow: hidden;
}

.bk-back {
  transform: rotateY(180deg);
  border-radius: 12px 0 0 12px;
}

.bk-leaf-cover .bk-front {
  border-radius: 3px 12px 12px 3px;
}

.bk-leaf-cover .bk-back {
  border-radius: 12px 3px 3px 12px;
}

/* Page base */
.bk-page {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Cover page */
.bk-cover {
  background: linear-gradient(135deg, #060d1f 0%, #0a1628 40%, #060d1f 100%);
  border-left: 4px solid rgba(0,229,255,.3);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
}

.bk-cover-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: .6rem;
  letter-spacing: .2em;
  color: rgba(0,229,255,.6);
  text-transform: uppercase;
  border: 1px solid rgba(0,229,255,.2);
  border-radius: 4px;
  padding: 3px 10px;
}

.bk-cover h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 800;
  color: #fff;
  line-height: 1.15;
  margin: 0;
}

.bk-cover h2 em {
  color: var(--a2);
  font-style: normal;
}

.bk-cover p {
  font-family: 'Space Grotesk', sans-serif;
  font-size: .85rem;
  color: rgba(255,255,255,.5);
  max-width: 260px;
  line-height: 1.5;
  margin: 0;
}

.bk-cover-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--a2) 0%, var(--a3) 50%, var(--a2) 100%);
  opacity: .6;
}

.bk-cover-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(0,229,255,.08) 0%, transparent 70%);
  pointer-events: none;
}

/* Back cover */
.bk-back-cover {
  background: linear-gradient(135deg, #060d1f 0%, #0c1430 50%, #060d1f 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
}

.bk-back-cover h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
}

.bk-back-cover p {
  font-family: 'Space Grotesk', sans-serif;
  font-size: .8rem;
  color: rgba(255,255,255,.45);
  max-width: 240px;
  line-height: 1.5;
  margin: 0;
}

.bk-back-cover .bk-cta {
  margin-top: 8px;
  display: inline-block;
  padding: 8px 20px;
  border: 1px solid rgba(0,229,255,.35);
  border-radius: 6px;
  color: var(--a2);
  font-family: 'JetBrains Mono', monospace;
  font-size: .7rem;
  letter-spacing: .1em;
  text-decoration: none;
  transition: background .2s, border-color .2s;
}

.bk-back-cover .bk-cta:hover {
  background: rgba(0,229,255,.08);
  border-color: rgba(0,229,255,.6);
}

/* Inner content pages */
.bk-content-page {
  background: linear-gradient(160deg, #07101f 0%, #0b1628 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 28px 24px 24px;
  gap: 10px;
  height: 100%;
  box-sizing: border-box;
}

/* Spine divider line */
.bk-spine-line {
  position: absolute;
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(0,229,255,.15) 20%, rgba(0,229,255,.15) 80%, transparent);
  pointer-events: none;
  z-index: 5;
}

/* Page number */
.bk-pg-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: .6rem;
  color: rgba(0,229,255,.3);
  letter-spacing: .1em;
  margin-bottom: 2px;
}

/* Entry heading */
.bk-entry-tag {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: .6rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--a2);
  background: rgba(0,229,255,.07);
  border: 1px solid rgba(0,229,255,.15);
  border-radius: 4px;
  padding: 2px 8px;
  margin-bottom: 4px;
}

.bk-entry-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.1rem, 2.5vw, 1.4rem);
  font-weight: 800;
  color: #fff;
  margin: 0 0 4px;
  line-height: 1.1;
}

.bk-entry-title em {
  color: var(--a2);
  font-style: normal;
}

.bk-entry-def {
  font-family: 'Space Grotesk', sans-serif;
  font-size: .8rem;
  color: rgba(255,255,255,.65);
  line-height: 1.6;
  margin: 0 0 6px;
}

.bk-entry-analogy {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: rgba(0,229,255,.05);
  border-left: 2px solid rgba(0,229,255,.25);
  border-radius: 0 6px 6px 0;
  padding: 8px 10px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: .76rem;
  color: rgba(255,255,255,.5);
  line-height: 1.5;
}

.bk-entry-analogy::before {
  content: '\2192';
  color: var(--a2);
  flex-shrink: 0;
  margin-top: 1px;
}

.bk-entry-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.bk-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: .6rem;
  color: rgba(124,92,255,.8);
  background: rgba(124,92,255,.08);
  border: 1px solid rgba(124,92,255,.2);
  border-radius: 4px;
  padding: 2px 7px;
}

.bk-divider {
  width: 40px;
  height: 1px;
  background: linear-gradient(90deg, rgba(0,229,255,.4), transparent);
  margin: 2px 0;
}

/* Page edge glow */
.bk-page-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 70% 30%, rgba(0,229,255,.05) 0%, transparent 60%);
  pointer-events: none;
}

/* Glare effect */
.bk-glare {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    105deg,
    transparent 40%,
    rgba(255,255,255,.04) 50%,
    transparent 60%
  );
  pointer-events: none;
  transform: rotate(15deg);
  z-index: 50;
}

/* Page fold shadow */
.bk-fold-shadow {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.2));
  pointer-events: none;
  z-index: 20;
}

/* Controls bar */
.bk-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
}

.bk-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid rgba(0,229,255,.2);
  border-radius: 6px;
  background: rgba(0,229,255,.05);
  color: rgba(255,255,255,.7);
  font-family: 'JetBrains Mono', monospace;
  font-size: .65rem;
  letter-spacing: .1em;
  cursor: pointer;
  transition: all .2s;
  outline: none;
}

.bk-btn:hover:not(:disabled) {
  background: rgba(0,229,255,.12);
  border-color: rgba(0,229,255,.5);
  color: #fff;
}

.bk-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

.bk-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bk-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.bk-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid rgba(0,229,255,.3);
  background: transparent;
  cursor: pointer;
  padding: 0;
  transition: all .2s;
}

.bk-dot.bk-active {
  background: var(--a2);
  border-color: var(--a2);
  box-shadow: 0 0 6px rgba(0,229,255,.6);
}

/* Sound toggle */
.bk-sound-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(0,229,255,.15);
  border-radius: 6px;
  background: transparent;
  color: rgba(0,229,255,.4);
  cursor: pointer;
  padding: 0;
  transition: all .2s;
}

.bk-sound-btn:hover {
  color: var(--a2);
  border-color: rgba(0,229,255,.4);
  background: rgba(0,229,255,.05);
}

.bk-sound-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Keyboard hint */
.bk-hint {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  font-family: 'JetBrains Mono', monospace;
  font-size: .58rem;
  color: rgba(0,229,255,.25);
  letter-spacing: .08em;
  white-space: nowrap;
  pointer-events: none;
}

/* Book shadow */
.bk-shadow {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%) rotateX(70deg);
  width: 80%;
  height: 60px;
  background: radial-gradient(ellipse, rgba(0,229,255,.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 5;
}

/* Ambient glow under book */
.bk-ambient {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 200px;
  background: radial-gradient(ellipse at bottom, rgba(0,229,255,.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 2;
}

/* Cover back face: content confined to left half */
.bk-leaf-cover .bk-back .bk-content-page {
  padding-right: calc(50% + 8px);
}

/* Performance: GPU-composited layers for 3D elements */
.bk-book,
.bk-leaf,
.bk-canvas {
  will-change: transform;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .bk-hud { flex-direction: column; gap: 4px; top: 12px; }
  .bk-hud-title { font-size: .8rem; }
  .bk-hud-label { display: none; }
  .bk-controls { bottom: 12px; gap: 10px; }
  .bk-btn { padding: 7px 14px; font-size: .6rem; }
  .bk-hint { display: none; }

  /* No 3D tilt on mobile — prevents overflow:hidden clipping the rotated book */
  .bk-book {
    width: 94vw;
    height: 68vw;
    min-height: 290px;
    transform: none !important;
  }

  /* Compact pages */
  .bk-content-page { padding: 14px 10px 10px; gap: 6px; }
  .bk-entry-title { font-size: .9rem; line-height: 1.1; margin-bottom: 2px; }
  .bk-entry-def { font-size: .72rem; line-height: 1.5; margin-bottom: 4px; }
  .bk-entry-analogy { display: none; }
  .bk-entry-pills { display: none; }
  .bk-divider { margin: 1px 0; }
  .bk-pg-num { font-size: .55rem; margin-bottom: 0; }
  .bk-entry-tag { font-size: .55rem; padding: 1px 6px; margin-bottom: 2px; }

  /* Cover compact */
  .bk-cover { gap: 10px; padding: 20px 16px; }
  .bk-cover h2 { font-size: 1.2rem; }
  .bk-cover p { font-size: .75rem; max-width: 200px; }

  .bk-spine-line { display: none; }

  /* Proper height for section on mobile — auto-height + padding for HUD/controls */
  .book-glossary {
    height: auto;
    min-height: 560px;
    padding: 75px 0 80px !important;
  }

  /* Prefácio second paragraph: hide to save vertical space */
  .bk-leaf-cover .bk-back .bk-content-page .bk-entry-def + .bk-entry-def { display: none; }
}

/* ================================================================
   MOBILE (<=820px) — COVERFLOW de cards
   O livro 3D de página dupla não funciona em telas estreitas. Aqui cada
   página vira um card de um carrossel "coverflow": o atual no centro,
   nítido; o anterior e o próximo espiando dos lados em 3D (scale +
   rotateY). Navegação por setas/swipe (JS). O livro 3D fica só no desktop.
   ================================================================ */
@media (max-width: 820px) {
  .bk-stage {
    perspective: 1200px;
    perspective-origin: center center;
    height: auto;
    display: block;
    padding: 0;
  }
  .bk-book {
    position: relative;
    width: 100%;
    height: 468px;
    min-height: 0;
    transform: none !important;
    transform-style: preserve-3d;
    cursor: default;
    overflow: visible;
  }
  /* As folhas não geram caixa (display:contents) — assim TODAS as faces se
     posicionam no mesmo espaço/perspectiva do .bk-book (senão cada folha
     criaria seu próprio contexto 3D e os cards não alinhariam). */
  .bk-leaf,
  .bk-leaf-cover {
    display: contents;
  }
  .bk-shadow { display: none; }
  /* cada face = um slide do coverflow (escondido por padrão) */
  .bk-front,
  .bk-back {
    position: absolute;
    inset: auto;
    top: 0;
    left: 50%;
    width: 76%;
    height: 100%;
    transform: translateX(-50%) scale(.78);
    opacity: 0;
    pointer-events: none;
    -webkit-backface-visibility: visible;
    backface-visibility: visible;
    overflow: hidden;
    border-radius: 20px !important;
    transition: transform .6s cubic-bezier(.34,1.3,.4,1), opacity .5s ease;
    will-change: transform, opacity;
  }
  .bk-front.bk-m-active,
  .bk-back.bk-m-active {
    transform: translateX(-50%) scale(1) rotateY(0deg);
    opacity: 1;
    z-index: 3;
    pointer-events: auto;
  }
  .bk-front.bk-m-prev,
  .bk-back.bk-m-prev {
    transform: translateX(-96%) scale(.82) rotateY(20deg);
    opacity: .5;
    z-index: 2;
  }
  .bk-front.bk-m-next,
  .bk-back.bk-m-next {
    transform: translateX(-4%) scale(.82) rotateY(-20deg);
    opacity: .5;
    z-index: 2;
  }
  .bk-page {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .bk-content-page {
    padding: 26px 22px !important;
    gap: 9px !important;
    justify-content: center;
  }
  /* borda-guia sempre à esquerda (cards uniformes) */
  .bk-left,
  .bk-right,
  .bk-cover {
    border-left: 4px solid rgba(0,229,255,.3) !important;
    border-right: 0 !important;
  }
  /* conteúdo legível dentro do card */
  .bk-entry-title { font-size: 1.5rem !important; line-height: 1.1 !important; }
  .bk-entry-def { font-size: .9rem !important; line-height: 1.55 !important; margin-bottom: 6px !important; }
  .bk-entry-def + .bk-entry-def { display: none; } /* 2º parágrafo: cabe melhor sem */
  .bk-entry-analogy { display: block !important; font-size: .82rem !important; }
  .bk-entry-pills { display: flex !important; }
  /* blur-reveal palavra por palavra: só o card ativo anima (os vizinhos
     mantêm o texto visível como contexto). */
  .bk-word { display: inline-block; }
  .bk-m-active .bk-word {
    animation: bkWordReveal .45s both;
    animation-delay: calc(var(--wi) * 25ms);
  }
  .bk-cover {
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 0;
    padding: 30px 24px !important;
  }
  .bk-cover h2 { font-size: 1.75rem !important; }
  .bk-cover p { font-size: .92rem !important; max-width: none !important; }
  /* nav: mantém setas + contador, esconde dots/som (10 cards) */
  .bk-dots,
  .bk-sound-btn { display: none !important; }
  .bk-controls { gap: 40px; }
  .bk-hint { display: none !important; }
}
@keyframes bkWordReveal {
  from { filter: blur(8px); opacity: 0; transform: translateY(6px); }
  to   { filter: blur(0);   opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .bk-m-active .bk-word { animation: none; }
}
