/* ==========================================================
   Flipbook CBB — estilo inspirado no FlipHTML5
   Cores em variáveis: ajuste --bg-1/--bg-2/--accent à vontade
   ========================================================== */
:root {
  --bg-1: #1f3f30;              /* centro do fundo */
  --bg-2: #08140e;              /* borda do fundo */
  --accent: #d4a640;            /* dourado (botão ativo, miniatura atual) */
  --accent-2: #b3202b;          /* vermelho natalino (detalhes) */
  --bar-bg: rgba(14, 18, 16, .88);
  --bar-fg: #f4f4f2;
  --bar-h: 64px;
  --top-h: 50px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg-2); color: var(--bar-fg); font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }
.tb-btn svg, .nav-arrow svg { fill: currentColor; }

/* ---------- Layout ---------- */
.app {
  position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, var(--bg-1) 0%, var(--bg-2) 78%);
}
.app::before {                      /* textura sutil */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .35;
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 22px 22px;
}

.topbar {
  height: var(--top-h); flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; z-index: 5; position: relative;
  background: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,0));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { height: 30px; width: auto; }
.brand-title { font-weight: 600; font-size: 15px; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { opacity: .65; font-size: 13px; white-space: nowrap; }
.brand-sub:not(:empty)::before { content: "•"; margin-right: 10px; opacity: .6; }
.topbar-right { display: flex; gap: 4px; }

.stage { flex: 1 1 auto; position: relative; overflow: hidden; touch-action: none; min-height: 0; }
.zoom-layer {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.book-wrap { position: relative; flex: 0 0 auto; transition: transform .5s ease; }
.is-zoomed .book-wrap { transition: none; }
.is-zoomed #book { pointer-events: none; }
.is-zoomed .stage { cursor: grab; }
.is-zoomed.is-panning .stage { cursor: grabbing; }

/* ---------- Livro (StPageFlip) ---------- */
#book { min-width: 0 !important; min-height: 0 !important; }
.stf__parent { position: relative; display: block; box-sizing: border-box; transform: translateZ(0); touch-action: pan-y; }
.stf__wrapper { position: relative; width: 100%; box-sizing: border-box; transition: none; }
.stf__parent canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; }
.stf__block { position: absolute; width: 100%; height: 100%; box-sizing: border-box; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow { position: absolute; left: 0; top: 0; }

.page { background: #fff; overflow: hidden; box-shadow: 0 12px 34px rgba(0,0,0,.45); }
.page-inner { width: 100%; height: 100%; position: relative; background: #f3f1ec; }
.page-inner img {
  width: 100%; height: 100%; display: block; object-fit: cover;
  user-select: none; -webkit-user-drag: none; pointer-events: none;
}
.page-inner::after {                /* sombra da lombada */
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.page.--left .page-inner::after  { background: linear-gradient(to left,  rgba(0,0,0,.16), rgba(0,0,0,0) 10%); }
.page.--right .page-inner::after { background: linear-gradient(to right, rgba(0,0,0,.16), rgba(0,0,0,0) 10%); }

/* ---------- Setas laterais ---------- */
.nav-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 4;
  width: 50px; height: 50px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.42); color: #fff; display: flex; align-items: center; justify-content: center;
  opacity: .8; transition: opacity .2s, background .2s, transform .2s;
}
.nav-arrow svg { width: 30px; height: 30px; }
.nav-arrow:hover { opacity: 1; background: rgba(0,0,0,.7); }
.nav-arrow:active { transform: translateY(-50%) scale(.94); }
.nav-arrow[disabled] { opacity: .12; cursor: default; pointer-events: none; }
.nav-prev { left: 16px; }
.nav-next { right: 16px; }

/* ---------- Barra de ferramentas ---------- */
.toolbar {
  flex: 0 0 auto; height: var(--bar-h); display: flex; justify-content: center; align-items: flex-end;
  padding: 0 8px 10px; z-index: 6; position: relative;
}
.toolbar-inner {
  display: flex; align-items: center; gap: 2px;
  background: var(--bar-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 14px; padding: 5px 8px; box-shadow: 0 10px 30px rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.06);
}
.tb-btn {
  width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--bar-fg);
  cursor: pointer; display: flex; align-items: center; justify-content: center; position: relative;
  text-decoration: none; flex: 0 0 auto; transition: background .15s; touch-action: manipulation;
}
.tb-btn:hover { background: rgba(255,255,255,.12); }
.tb-btn:active { background: rgba(255,255,255,.2); }
.tb-btn[disabled] { opacity: .3; cursor: default; pointer-events: none; }
.tb-btn.is-active { background: var(--accent); color: #1a1a1a; }
.tb-btn svg { width: 22px; height: 22px; }
.tb-btn .ico-off, .tb-btn .ico-pause { display: none; }
.tb-btn.is-off .ico-on, .tb-btn.is-off .ico-play { display: none; }
.tb-btn.is-off .ico-off, .tb-btn.is-off .ico-pause { display: block; }
.tb-btn-label { width: auto; padding: 0 12px 0 10px; gap: 7px; font-size: 13px; font-weight: 600; }
.tb-btn-label .tb-label { white-space: nowrap; }
.tb-btn-dark { color: #444; }
.tb-btn-dark:hover { background: rgba(0,0,0,.08); }
.tb-sep { width: 1px; height: 26px; background: rgba(255,255,255,.14); margin: 0 6px; flex: 0 0 auto; }

.page-ctrl { display: flex; align-items: center; gap: 6px; font-size: 14px; padding: 0 6px; }
.page-ctrl input {
  width: 62px; height: 32px; text-align: center; border-radius: 8px; font-size: 14px; color: #fff;
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); outline: none; font-family: inherit;
}
.page-ctrl input:focus { border-color: var(--accent); }
.page-sep { opacity: .6; }

/* ---------- Miniaturas ---------- */
.thumbs {
  position: absolute; left: 0; right: 0; bottom: var(--bar-h); z-index: 5;
  background: rgba(10, 14, 12, .93); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transform: translateY(calc(100% + var(--bar-h) + 10px)); visibility: hidden;
  transition: transform .3s ease, visibility 0s .3s; padding: 12px 16px 8px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.thumbs.is-open { transform: none; visibility: visible; transition: transform .3s ease, visibility 0s; }
.thumbs-list { display: flex; gap: 10px; overflow-x: auto; scroll-behavior: smooth; padding-bottom: 8px; scrollbar-width: thin; }
.thumb {
  flex: 0 0 auto; border: 2px solid transparent; border-radius: 6px; background: transparent; padding: 0;
  cursor: pointer; position: relative; transition: border-color .15s, transform .15s;
}
.thumb:hover { transform: translateY(-2px); }
.thumb img { height: 120px; width: auto; display: block; border-radius: 4px; background: #fff; }
.thumb span {
  position: absolute; bottom: 5px; right: 5px; background: rgba(0,0,0,.65); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 10px;
}
.thumb.is-active { border-color: var(--accent); }
.thumb.is-active span { background: var(--accent); color: #1a1a1a; }

/* ---------- Lista de catálogos ---------- */
.books-panel {
  position: absolute; top: calc(var(--top-h) + 2px); right: 12px; width: min(92vw, 400px); max-height: 70vh;
  background: #fff; color: #222; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.5);
  display: none; flex-direction: column; overflow: hidden; z-index: 15;
}
.books-panel.is-open { display: flex; }
.books-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 8px 16px; border-bottom: 1px solid #eee; }
.books-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.books-list { overflow: auto; padding: 8px 10px 10px; }
.book-item {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: #222; background: #f6f6f6;
  border: 2px solid transparent; border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; transition: background .15s;
}
.book-item:hover { background: #eee; }
.book-item.is-current { border-color: var(--accent); background: #fff8e6; }
.book-item img { height: 76px; width: 54px; object-fit: cover; border-radius: 4px; background: #ddd; flex: 0 0 auto; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.book-item-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.book-item-text b { font-size: 14px; font-weight: 600; }
.book-item-text small { font-size: 12px; color: #666; line-height: 1.35; }

/* ---------- Busca ---------- */
.search-panel {
  position: absolute; top: calc(var(--top-h) + 2px); right: 12px; width: min(92vw, 400px); max-height: 62vh;
  background: #fff; color: #222; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.5);
  display: none; flex-direction: column; overflow: hidden; z-index: 15;
}
.search-panel.is-open { display: flex; }
.search-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 8px; border-bottom: 1px solid #eee; }
.search-head input {
  flex: 1; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; outline: none; font-family: inherit;
}
.search-head input:focus { border-color: var(--accent); }
.search-results { overflow: auto; padding: 8px 10px 10px; }
.search-empty { color: #777; font-size: 13px; padding: 8px 4px; }
.search-item {
  display: block; width: 100%; text-align: left; border: 0; background: #f6f6f6; border-radius: 8px;
  padding: 8px 10px; margin-bottom: 6px; cursor: pointer; font-size: 13px; line-height: 1.35; color: #222;
}
.search-item:hover { background: #eee; }
.search-item b { color: var(--accent-2); margin-right: 6px; }
.search-item mark { background: #ffe7a3; padding: 0 1px; border-radius: 2px; }

/* ---------- Modal compartilhar ---------- */
.modal {
  position: absolute; inset: 0; z-index: 20; display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); padding: 16px;
}
.modal.is-open { display: flex; }
.modal-card {
  background: #fff; color: #222; border-radius: 14px; padding: 18px 20px 16px; width: min(100%, 440px);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.share-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.share-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none; color: #333;
  font-size: 12px; border: 1px solid #e6e6e6; border-radius: 10px; padding: 12px 6px; background: #fafafa; cursor: pointer;
  transition: background .15s, transform .15s;
}
.share-btn:hover { background: #f0f0f0; transform: translateY(-1px); }
.share-btn svg { width: 28px; height: 28px; }
.share-link { display: flex; gap: 8px; margin-top: 14px; }
.share-link input { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid #ddd; border-radius: 8px; font-size: 13px; font-family: inherit; }
.btn-primary {
  border: 0; border-radius: 8px; padding: 0 14px; background: var(--accent-2); color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
}
.btn-primary:hover { filter: brightness(1.1); }
.share-opt { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #555; margin-top: 12px; }

/* ---------- Loader / Toast ---------- */
.loader {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; z-index: 30; color: rgba(255,255,255,.85); font-size: 14px; transition: opacity .4s;
  background: radial-gradient(ellipse at 50% 38%, var(--bg-1) 0%, var(--bg-2) 78%);
}
.loader.is-hidden { opacity: 0; pointer-events: none; }
.loader.is-error { z-index: 3; }        /* fica abaixo da lista de catálogos, para o usuário escolher outro */
.loader.is-error .spinner { display: none; }
.app.is-error .nav-arrow, .app.is-error .toolbar-inner { display: none; }
.loader p { margin: 0; padding: 0 24px; text-align: center; max-width: 520px; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 10px); background: rgba(0,0,0,.85); color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: .25s; pointer-events: none; z-index: 40; white-space: nowrap;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsivo ---------- */
@media (max-width: 720px) {
  :root { --bar-h: 58px; --top-h: 44px; }
  .nav-arrow { display: none; }
  .brand-sub, .hide-sm, .tb-label { display: none; }
  .tb-btn-label { width: 36px; padding: 0; }
  .toolbar { padding: 0 6px 8px; }
  .toolbar-inner { width: 100%; justify-content: space-between; border-radius: 12px; padding: 4px 4px; }
  .tb-btn { width: 36px; height: 36px; }
  .tb-sep { margin: 0 2px; }
  .page-ctrl { padding: 0 2px; font-size: 13px; gap: 4px; }
  .page-ctrl input { width: 50px; height: 30px; }
  .thumb img { height: 84px; }
  .thumbs { padding: 10px 10px 6px; }
  .share-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 400px) {
  .hide-xs { display: none; }
  .tb-btn { width: 34px; height: 34px; }
}
@media (max-height: 480px) {
  :root { --top-h: 36px; }
}
