/* ==========================================================================
   Trilhando Sonhos - Carrossel Fotográfico das Galerias do Livro
   Moderno, Leve, Responsivo e Otimizado para Mobile (QR Codes)
   ========================================================================== */

:root {
  --bg-primary: #0a0d12;
  --bg-surface: #161b22;
  --bg-overlay: rgba(10, 13, 18, 0.85);
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --accent-color: #f05222;
  --accent-hover: #ff6b3d;
  --border-color: rgba(255, 255, 255, 0.1);
  --header-height: 56px;
  --thumbs-height: 74px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Container Principal em Altura Total */
.gallery-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
  background: radial-gradient(circle at 50% 30%, #151b23 0%, var(--bg-primary) 70%);
}

/* ==========================================================================
   Header Superior
   ========================================================================== */
.gallery-header {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 90px;
}

.header-right {
  justify-content: flex-end;
}

.header-title-wrap {
  text-align: center;
  flex: 1;
  min-width: 0;
  padding: 0 8px;
}

.chapter-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-color);
  margin-bottom: 2px;
}

.gallery-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.header-counter {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  min-width: 58px;
  text-align: center;
}

/* ==========================================================================
   Área Principal do Carrossel (Stage)
   ========================================================================== */
.gallery-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y;
}

.image-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
}

.main-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  transition: opacity 0.25s ease, transform 0.25s ease;
  cursor: pointer;
}

.main-image.loading {
  opacity: 0.3;
}

/* Botões de Navegação Flutuantes (Anterior / Próximo) */
.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  z-index: 10;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.nav-arrow:hover {
  background: var(--accent-color);
  border-color: var(--accent-color);
  transform: translateY(-50%) scale(1.1);
}

.nav-prev {
  left: 16px;
}

.nav-next {
  right: 16px;
}

/* Barra de Legenda */
.caption-bar {
  flex-shrink: 0;
  width: 100%;
  max-width: 800px;
  padding: 8px 16px 12px;
  text-align: center;
  z-index: 10;
}

.caption-text {
  display: inline-block;
  padding: 6px 16px;
  background: rgba(22, 27, 34, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-primary);
  max-width: 100%;
  word-break: break-word;
  transition: opacity 0.2s ease;
}

.caption-text:empty {
  display: none;
}

/* ==========================================================================
   Trilho de Miniaturas (Bottom Thumbnails)
   ========================================================================== */
.gallery-thumbs {
  height: var(--thumbs-height);
  flex-shrink: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 12px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  -webkit-overflow-scrolling: touch;
  z-index: 20;
}

.gallery-thumbs::-webkit-scrollbar {
  height: 4px;
}

.gallery-thumbs::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.thumb-item {
  position: relative;
  flex: 0 0 74px;
  height: 52px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  opacity: 0.5;
  transition: all 0.2s ease;
  background: #000;
}

.thumb-item:hover {
  opacity: 0.85;
}

.thumb-item.active {
  opacity: 1;
  border-color: var(--accent-color);
  box-shadow: 0 0 10px rgba(240, 82, 34, 0.5);
  transform: scale(1.05);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ==========================================================================
   Barra de Capítulos (Navegação Anterior / Próximo Capítulo)
   ========================================================================== */
.chapter-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: rgba(10, 13, 18, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  color: var(--text-secondary);
}

.chapter-nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s;
}

.chapter-nav-link:hover {
  color: var(--accent-color);
}

/* ==========================================================================
   Modo Tela Cheia (Fullscreen Overlay)
   ========================================================================== */
:fullscreen .gallery-app,
:-webkit-full-screen .gallery-app {
  width: 100vw;
  height: 100vh;
}

/* ==========================================================================
   Ajustes Responsivos Mobile (Smartphones)
   ========================================================================== */
@media (max-width: 640px) {
  :root {
    --header-height: 50px;
    --thumbs-height: 64px;
  }

  .gallery-header {
    padding: 0 10px;
  }

  .gallery-title {
    font-size: 14px;
  }

  .header-btn span {
    display: none;
  }

  .header-btn {
    padding: 0 8px;
    font-size: 12px;
  }

  .nav-arrow {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .nav-prev {
    left: 8px;
  }

  .nav-next {
    right: 8px;
  }

  .caption-text {
    font-size: 13px;
    padding: 5px 12px;
  }

  .thumb-item {
    flex: 0 0 60px;
    height: 44px;
  }
}
