/* =========================================================
   O Último Sheikah — Biblioteca / Acervo
   Estantes de livros (capas) + leitor com virada de página
   Depende das variáveis e fontes de styles.css
   ========================================================= */

.library-page {
  background:
    linear-gradient(rgba(5, 11, 22, 0.85), rgba(5, 11, 22, 0.85)),
    url("assets/img/blue.webp") center / cover no-repeat fixed var(--navy-900);
  min-height: 100vh;
}

/* ---------- Topbar simples ---------- */
.lib-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--navy-900) 82%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid color-mix(in srgb, var(--blue) 18%, transparent);
}
.lib-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--cyan);
  font-weight: 700;
  font-size: 0.95rem;
}
.lib-back:hover { text-decoration: underline; }
.lib-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  letter-spacing: 1px;
}
.lib-brand img { width: 30px; height: auto; filter: drop-shadow(0 0 8px rgba(63,169,255,0.5)); }
.lib-topbar-right { display: flex; align-items: center; gap: 16px; }

/* ---------- Hero da biblioteca (padrão do blog) ---------- */
.lib-hero {
  text-align: center;
  padding: 128px 20px 40px;
  background:
    url("assets/img/pattern-triforce.webp") repeat,
    linear-gradient(180deg, rgba(8, 18, 35, 0.55), rgba(5, 11, 22, 0.8));
  background-size: 110px auto, auto;
  border-bottom: 1px solid rgba(63, 169, 255, 0.12);
}
.lib-hero h1 {
  font-size: clamp(2.4rem, 6vw, 4rem);
  text-shadow:
    0 0 14px rgba(91, 192, 255, 0.5),
    0 0 40px rgba(63, 169, 255, 0.4);
  margin: 6px 0 16px;
}
.lib-hero p {
  color: var(--muted);
  font-size: 1.08rem;
  max-width: 560px;
  margin: 0 auto 20px;
}
.lib-hero .runes { font-size: 1.2rem; display: block; }

/* ---------- Estantes ---------- */
.lib-main { padding: 30px 0 80px; }

/* Estados da biblioteca em runtime (carregando / vazio / erro) */
.lib-state {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  font-size: 1.05rem;
}

.shelf-section { margin-bottom: 72px; }

.shelf-head {
  margin-bottom: 26px;
  padding-left: 4px;
}
.shelf-head h2 {
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  color: var(--gold);
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.shelf-head h2::before {
  content: "⌖";
  font-family: "Sheikah", sans-serif;
  color: var(--blue);
  font-size: 0.8em;
  text-shadow: var(--glow);
}
.shelf-head p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 0.98rem;
}

.shelf { position: relative; }
/* Grade de capas (tomos exibidos de frente) */
.shelf-books {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 24px;
  padding: 0 2px;
}
.shelf-plank { display: none; }

/* ---------- Livro (capa) ---------- */
.book {
  position: relative;
  cursor: pointer;
  color: var(--cream);
}
.book__inner { position: relative; width: 100%; height: 100%; }
.book__spine { display: none; }

.book__cover {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 272px;
  border-radius: 4px 8px 8px 4px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 50% 16%, rgba(240, 198, 116, 0.22), transparent 58%),
    linear-gradient(160deg, color-mix(in srgb, var(--cover, #122747) 80%, #ffffff 6%), var(--cover, #122747));
  border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  border-left: 4px solid color-mix(in srgb, var(--cream) 60%, transparent);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}
.book:hover .book__cover,
.book:focus-visible .book__cover {
  transform: translateY(-10px);
  border-color: color-mix(in srgb, var(--cyan) 60%, transparent);
  box-shadow:
    0 0 26px rgba(63, 169, 255, 0.4),
    0 24px 42px rgba(0, 0, 0, 0.55);
}
.book__seal {
  font-family: "Sheikah", sans-serif;
  font-size: 1.7rem;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(240, 198, 116, 0.6);
  margin-bottom: 8px;
}
.book__title {
  font-family: var(--book-title-font, "Hylia Serif", serif);
  font-size: var(--book-title-size, 1.12rem);
  line-height: 1.25;
  color: var(--book-title-fg, var(--cream));
  margin-bottom: 6px;
}
.book__sub {
  font-family: var(--book-sub-font, "Hylia Serif", serif);
  font-size: var(--book-sub-size, 0.9rem);
  line-height: 1.4;
  color: var(--book-sub-fg, color-mix(in srgb, var(--cream) 72%, transparent));
  flex: 1;
  overflow: hidden;
  margin: 0;
}
.book__open {
  margin-top: 10px;
  font-family: "Calamity", sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--cyan);
  letter-spacing: 0.5px;
}

/* ---------- Rodapé ---------- */
.lib-footer {
  text-align: center;
  padding: 40px 24px 60px;
  color: var(--muted);
  font-size: 0.88rem;
}
.lib-footer .runes { display: block; margin-bottom: 14px; font-size: 1rem; }

@media (max-width: 540px) {
  .shelf-books { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
  .book__cover { min-height: 240px; padding: 18px 16px; }
}

/* =========================================================
   Leitor com virada de página (StPageFlip)
   ========================================================= */
.reader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.reader[hidden] { display: none; }
.reader__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 7, 15, 0.86);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: readerFade 0.25s ease;
}
.reader__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  animation: readerOpen 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Toolbar: [‹]  estante/título  [›] [✕] */
.reader__toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(92vw, 720px);
  max-width: 100%;
}
.reader__heading {
  flex: 1;
  min-width: 0;
  text-align: center;
}
.reader__shelf {
  display: block;
  font-family: "Calamity", "Segoe UI", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cyan);
  opacity: 0.85;
  margin-bottom: 2px;
}
.reader__shelf:empty { display: none; }
.reader__title {
  font-family: "Hylia Serif", serif;
  font-size: clamp(1.05rem, 2.6vw, 1.5rem);
  color: var(--cream);
  text-shadow: 0 0 16px rgba(63, 169, 255, 0.4);
  line-height: 1.15;
}
.reader__close,
.reader__booknav-btn {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--muted) 40%, transparent);
  background: transparent;
  color: var(--ivory);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s, border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.reader__close { font-size: 1.1rem; }
.reader__close:hover { background: color-mix(in srgb, var(--cyan) 18%, transparent); transform: rotate(90deg); }
.reader__booknav-btn {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--cyan);
  border-color: rgba(63, 169, 255, 0.3);
}
.reader__booknav-btn:hover:not(:disabled) { border-color: var(--blue); box-shadow: var(--glow); }
.reader__booknav-btn:disabled { opacity: 0.25; cursor: default; }

/* Navegação repetida no fim do conteúdo (livro anterior / próximo) */
.reader__booknav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 2.4em;
  padding-top: 1.5em;
  border-top: 1px solid rgba(63, 169, 255, 0.2);
}
.reader__booknav-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 48%;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
}
.reader__booknav-link--next { margin-left: auto; text-align: right; align-items: flex-end; }
.reader__booknav-dir { font-size: 0.82em; color: var(--cyan); }
.reader__booknav-name { font-family: "Hylia Serif", serif; color: var(--cream); line-height: 1.2; }
.reader__booknav-link:hover .reader__booknav-name { text-decoration: underline; }

/* ---------- Modal de leitura (Markdown -> HTML) ----------
   Leitura simples no tema do site (Sheikah / dark). NÃO usa as cores/fontes/
   tamanhos do `style` do livro de propósito (essa formatação fica só nas
   estantes). */
.reader__content {
  width: min(92vw, 720px);
  max-height: 80vh;
  overflow-y: auto;
  padding: clamp(28px, 5vw, 52px);
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--navy-700), var(--navy-800));
  border: 1px solid rgba(63, 169, 255, 0.2);
  color: var(--ivory);
  font-family: "Calamity", "Segoe UI", system-ui, sans-serif;
  font-size: clamp(1rem, 2.4vw, 1.08rem);
  line-height: 1.8;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), var(--glow);
  text-align: left;
}
.reader__content > :first-child { margin-top: 0; }
.reader__content > :last-child { margin-bottom: 0; }
.reader__content h1,
.reader__content h2,
.reader__content h3,
.reader__content h4 {
  font-family: "Hylia Serif", serif;
  color: var(--cream);
  line-height: 1.25;
  margin: 1.6em 0 0.5em;
}
.reader__content h1 { font-size: 1.7em; color: var(--blue-glow); text-shadow: var(--glow); }
.reader__content h2 { font-size: 1.4em; }
.reader__content h3 { font-size: 1.18em; }
.reader__content p { margin: 0 0 1em; color: var(--ivory); }
.reader__content ul,
.reader__content ol { margin: 0 0 1em; padding-left: 1.5em; }
.reader__content li { margin-bottom: 0.4em; }
.reader__content a { color: var(--cyan); text-decoration: underline; }
.reader__content a:hover { color: var(--blue-glow); }
.reader__content blockquote {
  margin: 1em 0;
  padding: 0.4em 1.1em;
  border-left: 3px solid var(--blue);
  color: var(--muted);
  font-style: italic;
}
.reader__content code {
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.35);
  color: var(--cyan);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.reader__content pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
}
.reader__content pre code { background: none; padding: 0; color: var(--ivory); }
.reader__content hr { border: 0; border-top: 1px solid rgba(63, 169, 255, 0.2); margin: 1.6em 0; }
.reader__content img { max-width: 100%; height: auto; border-radius: 6px; }
.reader__content strong { color: var(--cream); }

/* Palco onde o livro é montado pela StPageFlip.
   As variáveis --book-* são preenchidas em runtime pelo JS com o `style` de
   cada livro vindo da API (cores, fontes e tamanhos). Os valores abaixo são só
   o fallback caso um livro não traga style. */
.reader__stage {
  --book-cover: #122747;
  --book-paper: #f5ecd7;
  --book-title-font: "Hylia Serif", serif;
  --book-title-size: 22px;
  --book-title-fg: #f1f5f9;
  --book-sub-font: "Hylia Serif", serif;
  --book-sub-size: 13px;
  --book-sub-fg: #d8c7a0;
  --book-head-font: "Hylia Serif", serif;
  --book-head-size: 22px;
  --book-head-fg: #3a2a14;
  --book-content-font: Georgia, "Times New Roman", serif;
  --book-content-size: 16px;
  --book-content-fg: #2b2620;
  margin: 0 auto;
}

/* Páginas */
.flip-page { background: transparent; }
.flip-page__inner {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 34px 30px 40px;
  overflow: hidden;
  background: var(--book-paper);
  color: var(--book-content-fg);
  font-family: var(--book-content-font);
  font-size: var(--book-content-size);
  line-height: 1.72;
  position: relative;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.07);
}
.flip-page__inner p {
  margin-bottom: 12px;
  text-align: justify;
  hyphens: auto;
}
/* Cabeçalhos DENTRO do conteúdo (não na capa — senão sobrescreveriam o título) */
.flip-page__inner:not(.flip-cover) h1,
.flip-page__inner:not(.flip-cover) h2,
.flip-page__inner:not(.flip-cover) h3,
.flip-page__inner:not(.flip-cover) h4 {
  font-family: var(--book-head-font);
  color: var(--book-head-fg);
  font-size: var(--book-head-size);
  line-height: 1.2;
  margin: 0 0 12px;
}
.flip-page__inner a { color: color-mix(in srgb, var(--book-cover) 70%, var(--book-content-fg)); }
.flip-folio {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.74rem;
  color: var(--book-content-fg);
  opacity: 0.5;
  font-family: var(--book-head-font);
}

/* Capa / contracapa internas (folhas duras) */
.flip-cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(240, 198, 116, 0.25), transparent 60%),
    linear-gradient(160deg, color-mix(in srgb, var(--book-cover) 82%, #fff 6%), var(--book-cover));
  color: var(--cream);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.25);
}
.flip-cover__seal {
  font-family: "Sheikah", sans-serif;
  font-size: 2.4rem;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(240, 198, 116, 0.6);
  margin-bottom: 14px;
}
.flip-cover__title {
  font-family: var(--book-title-font);
  font-size: var(--book-title-size);
  line-height: 1.2;
  color: var(--book-title-fg);
  padding: 0 18px;
  margin-bottom: 16px;
}
.flip-cover__sub {
  font-family: var(--book-sub-font);
  font-size: var(--book-sub-size);
  color: var(--book-sub-fg);
  padding: 0 22px;
  margin: -8px 0 18px;
}
.flip-cover__runes {
  font-family: "Sheikah", sans-serif;
  color: var(--blue-glow);
  opacity: 0.7;
  letter-spacing: 2px;
  font-size: 0.85rem;
}
.flip-end {
  font-family: "Hylia Serif", serif;
  font-size: 1.05rem;
  color: var(--cream);
  padding: 0 24px;
}

/* Controles */
.reader__controls {
  display: flex;
  align-items: center;
  gap: 22px;
}
.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, transparent);
  background: color-mix(in srgb, var(--navy-700) 70%, transparent);
  color: var(--cyan);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}
.nav-btn:hover { background: var(--navy-600); box-shadow: var(--glow); }
.reader__page-num {
  min-width: 64px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-family: "Calamity", sans-serif;
}

@keyframes readerFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes readerOpen {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .reader__backdrop, .reader__panel { animation: none; }
}

/* ============================================================
   Bibliotecário + Chatbot da base de conhecimento
   ============================================================ */
.librarian {
  padding: 28px 20px 8px;
}
.librarian__inner {
  display: flex;
  gap: 28px;
  align-items: stretch;
  justify-content: center;
}

/* ---- Figura do bibliotecário ---- */
.librarian__figure {
  flex: 0 0 220px;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.librarian__avatar {
  width: 100%;
  max-width: 220px;
  height: auto;
  filter: drop-shadow(0 0 22px rgba(63, 169, 255, 0.35));
  animation: librarianFloat 6s ease-in-out infinite;
}
.librarian__id {
  margin-top: 10px;
}
.librarian__name {
  display: block;
  font-family: "Hylia Serif", serif;
  font-size: 1.3rem;
  color: var(--cream);
  text-shadow: 0 0 14px rgba(91, 192, 255, 0.4);
}
.librarian__role {
  display: block;
  font-size: 0.85rem;
  color: var(--gold);
  letter-spacing: 0.04em;
}

/* ---- Caixa de chat ---- */
.chat {
  flex: 1 1 auto;
  max-width: 620px;
  display: flex;
  flex-direction: column;
  height: 440px;
  background: linear-gradient(180deg, rgba(10, 22, 40, 0.92), rgba(6, 13, 26, 0.96));
  border: 1px solid rgba(63, 169, 255, 0.22);
  border-radius: var(--radius);
  box-shadow: var(--glow), inset 0 0 40px rgba(8, 18, 35, 0.6);
  overflow: hidden;
}
.chat__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(63, 169, 255, 0.4) transparent;
}
.chat__log::-webkit-scrollbar { width: 8px; }
.chat__log::-webkit-scrollbar-thumb { background: rgba(63, 169, 255, 0.3); border-radius: 8px; }

.chat__msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.96rem;
  line-height: 1.5;
  white-space: normal;
  word-wrap: break-word;
}
.chat__msg--user {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(63, 169, 255, 0.9), rgba(45, 130, 210, 0.9));
  color: #08182a;
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chat__msg--bot {
  align-self: flex-start;
  background: rgba(20, 36, 58, 0.85);
  border: 1px solid rgba(63, 169, 255, 0.16);
  color: var(--ivory);
  border-bottom-left-radius: 4px;
}
.chat__msg--welcome {
  font-style: italic;
  color: var(--cream);
}
.chat__msg--error {
  color: #ffb4b4;
  border-color: rgba(255, 120, 120, 0.4);
}
.chat__cite {
  color: var(--cyan);
  font-size: 0.78em;
  font-weight: 600;
  vertical-align: super;
}
.chat__sources {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(63, 169, 255, 0.18);
  font-size: 0.76rem;
  color: var(--muted);
}

/* Indicador "digitando" */
.chat__dots { display: inline-flex; gap: 4px; }
.chat__dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--blue-glow);
  animation: chatDot 1.2s infinite ease-in-out;
}
.chat__dots i:nth-child(2) { animation-delay: 0.2s; }
.chat__dots i:nth-child(3) { animation-delay: 0.4s; }

/* ---- Formulário ---- */
.chat__form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(63, 169, 255, 0.18);
  background: rgba(6, 13, 26, 0.7);
}
.chat__input {
  flex: 1 1 auto;
  background: rgba(8, 18, 35, 0.9);
  border: 1px solid rgba(63, 169, 255, 0.25);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--ivory);
  font-size: 0.96rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat__input::placeholder { color: var(--muted); }
.chat__input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(63, 169, 255, 0.25);
}
.chat__send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--blue), #2d82d2);
  color: #08182a;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s;
}
.chat__send:hover { filter: brightness(1.12); }
.chat__send:active { transform: scale(0.95); }
.chat__send:disabled { opacity: 0.5; cursor: default; }
.chat__clear {
  align-self: flex-end;
  margin: 0 12px 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}
.chat__clear:hover { color: var(--ivory); }

@keyframes librarianFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes chatDot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

@media (max-width: 720px) {
  .librarian__inner { flex-direction: column; align-items: center; gap: 16px; }
  .librarian__figure { flex-basis: auto; }
  .librarian__avatar { max-width: 150px; }
  .chat { width: 100%; max-width: 100%; height: 60vh; min-height: 360px; }
}
@media (prefers-reduced-motion: reduce) {
  .librarian__avatar { animation: none; }
}
