/* === Reset & Base === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: only light;
  /* bloqueia tema escuro do sistema */
  --bg: #cce8f4;
  --apresentacao: #f5e06e;
  --ambientes: #aee09a;
  --flora: #d4cc65;
  --mamiferos: #9dd8d8;
  --aves: #f5b87a;
  --anuros: #f5a0a0;
  --card-radius: 14px;
  --btn-radius: 18px;
  --shadow: 0 3px 8px rgba(0, 0, 0, .18);
  /* safe areas — só têm valor quando viewport-fit=cover está ativo */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  width: 100%;
  forced-color-adjust: none;
  /* impede pull-to-refresh e rubber-band scroll no body */
  overscroll-behavior: none;
}

body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: Georgia, 'Times New Roman', serif;
  background: var(--bg);
  color: #1a1a1a;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button,
[onclick] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* === Views === */
.view {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.view.active {
  display: flex;
}

.view::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url('../assets/custom/img/fundo.webp');
  background-size: cover;
  background-position: center bottom;
  opacity: .35;
  pointer-events: none;
  z-index: -1;
}

/* === Scroll containers === */
.scroll-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-bottom: max(32px, calc(var(--sab) + 16px));
}

/* === HOME === */
#view-home {
  background: var(--bg);
  overflow: hidden;
}

.home-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(10px, calc(var(--sat) + 4px)) 20px max(80px, calc(var(--sab) + 76px));
  height: 100%;
  overflow: hidden;
  justify-content: center;
  gap: clamp(5px, 1.4vh, 11px);
}

.home-logo {
  width: 70%;
  height: auto;
  flex-shrink: 1;
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
  min-height: 44px;
  max-height: 64px;
  padding: 0 20px;
  margin-bottom: 0;
  border: none;
  border-radius: var(--btn-radius);
  font-family: Georgia, serif;
  font-size: clamp(1.05rem, 4.2vw, 1.35rem);
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.menu-btn:active {
  transform: scale(.97);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}

.btn-apresentacao {
  background: var(--apresentacao);
}

.btn-ambientes {
  background: var(--ambientes);
}

.btn-flora {
  background: var(--flora);
}

.btn-mamiferos {
  background: var(--mamiferos);
}

.btn-aves {
  background: var(--aves);
}

.btn-anuros {
  background: var(--anuros);
}

.qr-fab {
  position: fixed;
  bottom: max(24px, calc(var(--sab) + 16px));
  right: max(20px, calc(var(--sar) + 16px));
  z-index: 10;
  width: 68px;
  height: 68px;
  background: #fff;
  border: none;
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 6px;
  transition: transform .12s;
  touch-action: manipulation;
}

.qr-fab:active {
  transform: scale(.93);
}

.qr-fab img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* === HEADER (todas as sub-telas) === */
.view-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: max(14px, calc(var(--sat) + 8px)) max(16px, calc(var(--sal) + 12px)) 10px;
  gap: 8px;
  flex-shrink: 0;
}

.back-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .12s;
  padding: 0;
  touch-action: manipulation;
}

.back-btn img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.back-btn:active {
  opacity: .65;
}

.cat-badge {
  width: 100%;
  padding: clamp(12px, 3.5vw, 16px) 20px;
  border-radius: var(--btn-radius);
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  font-weight: bold;
  text-align: center;
  box-shadow: var(--shadow);
}

/* === GRID DE ESPÉCIES === */
.species-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 12px 24px;
}

.species-card {
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.species-card:active {
  transform: scale(.97);
}

.species-card img {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.species-label {
  padding: 8px 10px 10px;
  flex: 1;
}

.species-label .nome-popular {
  font-weight: bold;
  font-size: clamp(0.82rem, 3.5vw, 0.95rem);
  line-height: 1.25;
}

.species-label .nome-cientifico {
  font-style: italic;
  font-size: clamp(0.72rem, 3vw, 0.82rem);
  color: #1a1a1a;
  line-height: 1.25;
  margin-top: 3px;
}

/* === DETALHE DA ESPÉCIE === */
.detail-img {
  width: 90%;
  display: block;
  margin: 0 auto;
  height: auto;
}

.detail-video {
  width: 90%;
  display: block;
  margin: 0 auto;
  background: #000;
  height: auto;
}

.audio-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px auto;
  width: 68px;
  height: 68px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: opacity .12s;
  padding: 0;
  touch-action: manipulation;
}

.audio-btn img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.audio-btn:active {
  opacity: .7;
}

.info-card {
  margin: 12px 12px 24px;
  border-radius: var(--card-radius);
  padding: 18px;
  box-shadow: var(--shadow);
  background: rgba(255, 255, 255, 0.92);
}

.info-card h3 {
  font-size: 1.05rem;
  font-weight: bold;
  margin-top: 14px;
  color: #000;
}

.info-card h3:first-child {
  margin-top: 0;
}

.info-card .ambiente-titulo {
  font-size: 1.15rem;
  font-weight: bold;
  margin-top: 0;
  margin-bottom: 8px;
}

.info-card .sci {
  font-style: italic;
  font-size: 0.95rem;
  color: #222;
  margin-top: 4px;
}

.info-card .pop {
  font-size: 0.95rem;
  color: #222;
  margin-top: 4px;
}

.info-card p {
  font-size: 0.95rem;
  line-height: 1.7;
  margin-top: 6px;
  color: #111;
}

/* === APRESENTAÇÃO — cards de seleção === */
.apres-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  height: 100%;
  box-sizing: border-box;
}

.apres-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: var(--card-radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s;
  touch-action: manipulation;
}

.apres-card:active {
  transform: scale(.98);
}

.apres-card img {
  flex: 1 1 0;
  width: auto;
  max-width: 55%;
  min-height: 0;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  padding: 8px 0;
}

.apres-card-label {
  flex-shrink: 0;
  padding: 12px 16px;
  font-size: 1.1rem;
  font-weight: bold;
  text-align: center;
  background: var(--apresentacao);
}

/* === GUIA DO APP — vídeo === */
.apres-section {
  padding: 0 12px 12px;
}

.apres-section video {
  width: 90%;
  border-radius: 12px;
  display: block;
  margin: 0 auto;
  max-height: calc(100vh - 150px);
  object-fit: contain;
}

/* === QR SCANNER === */
#qr-reader {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

#qr-reader>* {
  width: 100% !important;
  max-width: 100% !important;
}

.qr-hint {
  text-align: center;
  padding: 14px;
  font-size: 1rem;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  flex-shrink: 0;
}

.qr-status {
  text-align: center;
  padding: 12px 16px;
  font-size: 1.05rem;
  background: rgba(0, 0, 0, .5);
  color: #fff;
  flex-shrink: 0;
}

/* === BANNER DE INSTALAÇÃO === */
.install-banner {
  position: fixed;
  bottom: max(16px, calc(var(--sab) + 12px));
  left: max(12px, calc(var(--sal) + 12px));
  right: max(12px, calc(var(--sar) + 12px));
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
  transform: translateY(120%);
  opacity: 0;
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1), opacity .3s ease;
  pointer-events: none;
}

.install-banner.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.install-banner-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.install-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.install-banner-text strong {
  font-size: 0.95rem;
  font-family: sans-serif;
  color: #111;
}

.install-banner-text span {
  font-size: 0.78rem;
  font-family: sans-serif;
  color: #555;
}

.install-banner-btn {
  background: #2d7d9a;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: bold;
  font-family: sans-serif;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.install-banner-btn:active {
  opacity: .8;
}

.install-banner-close {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: #888;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
  touch-action: manipulation;
  line-height: 1;
}

/* === MODO STANDALONE === */
@media (display-mode: standalone) {
  .view-header {
    padding-top: max(18px, calc(var(--sat) + 10px));
  }

  .home-inner {
    padding-top: max(18px, calc(var(--sat) + 12px));
  }
}

/* === RESPONSIVO — telefones pequenos === */
@media (max-width: 379px) {
  .home-logo {
    width: 70%;
  }

  .menu-btn {
    font-size: 0.98rem;
  }

  .cat-badge {
    font-size: 1rem;
    padding: 10px 16px;
  }

  .species-grid {
    gap: 8px;
    padding: 8px 8px 20px;
  }

  .species-label .nome-popular {
    font-size: 0.78rem;
  }

  .species-label .nome-cientifico {
    font-size: 0.68rem;
  }
}

/* === RESPONSIVO — tablets e telas largas (>= 600px) === */
@media (min-width: 600px) {
  .home-inner {
    max-width: 480px;
    margin: 0 auto;
  }

  .species-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    padding: 14px;
  }

  .menu-btn {
    font-size: 1.3rem;
  }

  .cat-badge {
    font-size: 1.3rem;
  }

  .info-card {
    margin: 16px auto;
    max-width: 560px;
  }

  .apres-cards {
    max-width: 560px;
    margin: 0 auto;
  }

  .install-banner {
    max-width: 500px;
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(120%);
  }

  .install-banner.visible {
    transform: translateX(-50%) translateY(0);
  }
}

/* === RESPONSIVO — PC / tablet (>= 768px) === */
@media (min-width: 768px) {

  .home-inner {
    max-width: 600px;
  }

  .view-header {
    flex-direction: row;
    align-items: center;
    align-self: center;
    width: 100%;
    max-width: 820px;
    box-sizing: border-box;
  }

  .view-header .cat-badge {
    flex: 1;
    width: auto;
  }

  .species-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    padding: 18px;
    max-width: 960px;
    margin: 0 auto;
  }

  .species-grid--ambientes {
    grid-template-columns: 1fr 1fr;
    max-width: 760px;
  }

  #detail-content {
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
  }

  .info-card {
    max-width: 700px;
    margin: 16px auto 28px;
  }

  .apres-cards {
    flex-direction: row;
    height: auto;
    max-width: 820px;
    margin-left: auto;
    margin-right: auto;
  }

  .apres-card {
    height: clamp(240px, 38vh, 380px);
  }

  .apres-section {
    max-width: 820px;
    margin: 0 auto;
  }

  .mapa-img {
    max-width: 760px;
  }

  .mapa-instrucao {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  .trilha-btns {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  .trilha-lista {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* === MAPA DA TRILHA === */
.mapa-img {
  width: 90%;
  display: block;
  margin: 8px auto 0;
  height: auto;
  border-radius: 8px;
}

.mapa-instrucao {
  text-align: center;
  padding: 10px 16px 6px;
  font-size: 0.9rem;
  color: #1a1a1a;
}

.trilha-btns {
  display: flex;
  gap: 12px;
  padding: 8px 16px 14px;
  justify-content: center;
}

.trilha-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 3px solid #666;
  background: #fff;
  font-size: 1.25rem;
  font-weight: bold;
  font-family: Georgia, serif;
  cursor: pointer;
  transition: all .15s;
  touch-action: manipulation;
  user-select: none;
}

.trilha-btn.active {
  background: #2d5fa0;
  color: #fff;
  border-color: #2d5fa0;
}

.trilha-btn:active {
  opacity: .7;
}

.trilha-lista {
  padding: 0 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trilha-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #d0ede8;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity .12s;
  user-select: none;
}

.trilha-item:active {
  opacity: .65;
}

.trilha-icn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}

.trilha-icn img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.trilha-nome {
  font-style: italic;
  font-size: 0.92rem;
  color: #111;
  line-height: 1.3;
}

/* === AMBIENTES — lista em coluna única === */
.species-grid--ambientes {
  grid-template-columns: 1fr;
}

.species-grid--ambientes .species-card img {
  aspect-ratio: 16/9;
}

/* === LIGHTBOX === */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, .65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox.open {
  display: flex;
}

.lightbox-window {
  position: relative;
  max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .6);
  background: #000;
  animation: lbIn .2s ease-out;
}

.lightbox-window img {
  display: block;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 80px);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.lightbox-close:active {
  opacity: .7;
}

.detail-img {
  cursor: zoom-in;
}

@keyframes lbIn {
  from {
    transform: scale(.88);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* === BOTÃO INSTALAR (home) === */
.install-home-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 0;
  padding: clamp(9px, 2.5vh, 14px) 28px;
  background: #2d7d9a;
  color: #fff;
  border: none;
  border-radius: var(--btn-radius);
  font-family: Georgia, serif;
  font-size: clamp(0.95rem, 3.8vw, 1.1rem);
  font-weight: bold;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  transition: opacity .15s;
  width: 100%;
}

.install-home-btn img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  border-radius: 6px;
}

.install-home-btn:active {
  opacity: .75;
}

/* === MODAL INSTALAR === */
.modal-instalar {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, .6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-instalar.open {
  display: flex;
}

.modal-instalar-box {
  background: #fff;
  border-radius: 18px;
  padding: 28px 22px 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .45);
  position: relative;
  animation: lbIn .2s ease-out;
}

.modal-instalar-box h3 {
  font-size: 1.2rem;
  font-weight: bold;
  margin-bottom: 14px;
  color: #111;
  text-align: center;
}

.modal-instalar-box>p {
  font-size: 0.92rem;
  color: #333;
  margin-bottom: 14px;
  line-height: 1.55;
}

.modal-instalar-box ol {
  padding-left: 20px;
  margin-bottom: 20px;
}

.modal-instalar-box ol li {
  font-size: 0.91rem;
  color: #222;
  line-height: 1.7;
  margin-bottom: 2px;
}

.modal-instalar-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: #888;
  cursor: pointer;
  padding: 4px 8px;
  touch-action: manipulation;
  line-height: 1;
}

.modal-instalar-close:active {
  opacity: .6;
}

.modal-instalar-copy {
  width: 100%;
  padding: 13px;
  background: #2d7d9a;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: bold;
  font-family: Georgia, serif;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity .15s;
}

.modal-instalar-copy:active {
  opacity: .75;
}

/* === ANIMAÇÕES DE TRANSIÇÃO === */
@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.view.slide-in {
  animation: slideIn .22s ease-out;
}

@keyframes slideBack {
  from {
    transform: translateX(-30%);
    opacity: .5;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.view.slide-back {
  animation: slideBack .22s ease-out;
}

/* ═══════════════════════════════════════════════════════════
   ÍCONES ANIMADOS NOS BOTÕES DA HOME  — VERSÃO CORRIGIDA
   SUBSTITUA todo o bloco "ÍCONES ANIMADOS" do final do style.css
   por este. A diferença-chave é o "transform-box: fill-box",
   que faz transform-origin funcionar dentro de SVG.
══════════════════════════════════════════════════════════════ */
.menu-btn--ico {
  position: relative;
}

.menu-btn--ico>span {
  display: block;
  text-align: center;
}

.mb-ico {
  position: absolute;
  left: 16px;
  top: 50%;
  width: 38px;
  height: 38px;
  margin-top: -19px;
  opacity: .92;
  pointer-events: none;
}

.mb-s {
  fill: none;
  stroke: #fff;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* CHAVE DA CORREÇÃO: cada elemento animado calcula sua própria
   caixa de referência. Sem isto, transform-origin em SVG falha. */
.mb-tree,
.mb-frog,
.mb-bird,
.mb-wing,
.mb-bloom,
.mb-bloom2,
.mb-paw {
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes mb-sway {

  0%,
  100% {
    transform: rotate(-6deg);
  }

  50% {
    transform: rotate(6deg);
  }
}

@keyframes mb-hop {

  0%,
  55%,
  100% {
    transform: translateY(0);
  }

  25% {
    transform: translateY(-4px);
  }

  40% {
    transform: translateY(0);
  }
}

@keyframes mb-fly {

  0%,
  100% {
    transform: translateY(1px);
  }

  50% {
    transform: translateY(-2px);
  }
}

@keyframes mb-wing {

  0%,
  100% {
    transform: scaleY(1);
  }

  50% {
    transform: scaleY(.5);
  }
}

@keyframes mb-bloom {

  0%,
  100% {
    transform: scale(.9);
  }

  50% {
    transform: scale(1.08);
  }
}

@keyframes mb-drift {

  0%,
  100% {
    transform: translate(0, 0);
  }

  50% {
    transform: translate(2px, -1px);
  }
}

.mb-tree {
  animation: mb-sway 3.5s ease-in-out infinite;
}

.mb-frog {
  animation: mb-hop 2.2s ease-in-out infinite;
}

.mb-bird {
  animation: mb-fly 2.6s ease-in-out infinite;
}

.mb-wing {
  transform-origin: left center;
  animation: mb-wing .7s ease-in-out infinite;
}

.mb-bloom {
  animation: mb-bloom 3s ease-in-out infinite;
}

.mb-bloom2 {
  animation: mb-bloom 3s ease-in-out infinite;
}

.mb-paw {
  animation: mb-drift 3s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {

  .mb-tree,
  .mb-frog,
  .mb-bird,
  .mb-wing,
  .mb-bloom,
  .mb-bloom2,
  .mb-paw {
    animation: none;
  }
}

@media (max-width: 379px) {
  .mb-ico {
    width: 32px;
    height: 32px;
    margin-top: -16px;
    left: 12px;
  }
}