:root {
  --noite: #1b2752;
  --noite-2: #26356b;
  --estrela: #f6c453;
  --estrela-forte: #f0a91c;
  --palha: #fff4d4;
  --manto: #4f86d0;
  --tinta: #26213a;
  --branco: #ffffff;
  --raio-g: 28px;
  --raio-p: 16px;
  --sombra: 0 6px 0 rgba(15, 20, 48, .35);
  --fonte: "Baloo 2", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--noite);
  color: var(--tinta);
  font-family: var(--fonte);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app { min-height: 100%; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible, a:focus-visible {
  outline: 4px solid var(--estrela);
  outline-offset: 3px;
}

img { display: block; max-width: 100%; }

/* ---------- céu estrelado (fundo das telas de navegação) ---------- */
.ceu {
  min-height: 100dvh;
  color: var(--palha);
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 8%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 44% 22%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 63% 12%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 78% 26%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 9%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 8% 40%, #fff8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 95% 44%, #fff8 50%, transparent 51%),
    linear-gradient(180deg, var(--noite) 0%, var(--noite-2) 100%);
  padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(28px + var(--safe-b)) calc(20px + var(--safe-l));
}

/* ---------- estante ---------- */
.estante { max-width: 1040px; margin: 0 auto; }

.estante h1 {
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1;
  font-weight: 800;
  margin: 8px 0 6px;
  color: var(--estrela);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .25);
}

.estante p.sub { margin: 0 0 28px; font-size: 1.15rem; opacity: .85; }

.livros {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 24px;
}

.livro {
  text-align: left;
  border-radius: var(--raio-g);
  overflow: hidden;
  background: var(--palha);
  color: var(--tinta);
  box-shadow: var(--sombra);
  transition: transform .15s;
}
.livro:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(15, 20, 48, .35); }
.livro img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.livro .info { padding: 14px 18px 18px; }
.livro h2 { margin: 0; font-size: 1.5rem; line-height: 1.1; font-weight: 800; }
.livro span { font-size: 1rem; opacity: .75; }

.em-breve {
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 3px dashed rgba(255, 244, 212, .35);
  border-radius: var(--raio-g);
  padding: 20px;
  text-align: center;
  font-size: 1.15rem;
  color: rgba(255, 244, 212, .75);
}

/* ---------- capa da história ---------- */
.capa {
  min-height: calc(100dvh - 52px - var(--safe-t) - var(--safe-b));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.topo { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.redondo {
  width: 64px;
  height: 64px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--palha);
  color: var(--noite);
  box-shadow: var(--sombra);
}
.redondo:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(15, 20, 48, .35); }
.redondo svg { width: 32px; height: 32px; }
.redondo.ouro { background: var(--estrela); }
.redondo[disabled] { opacity: .35; pointer-events: none; }

.capa-img {
  justify-self: center;
  width: min(100%, 980px, calc((100dvh - 400px) * 16 / 9));
  min-width: 260px;
  border-radius: var(--raio-g);
  overflow: hidden;
  box-shadow: 0 0 0 6px var(--palha), 0 18px 50px rgba(0, 0, 0, .45);
  align-self: center;
}
.capa-img img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }

.capa-titulo { text-align: center; }
.capa-titulo h1 {
  margin: 0;
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  line-height: .95;
  font-weight: 800;
  color: var(--estrela);
  text-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.capa-titulo p { margin: 8px 0 0; font-size: 1.2rem; }

.acoes { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }

.botao {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 10px 30px 8px;
  border-radius: 999px;
  font-size: 1.45rem;
  font-weight: 800;
  background: var(--estrela);
  color: var(--noite);
  box-shadow: var(--sombra);
}
.botao:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(15, 20, 48, .35); }
.botao svg { width: 30px; height: 30px; }
.botao.claro { background: var(--palha); }

/* ---------- leitor ---------- */
.leitor {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--noite);
  overflow: hidden;
}

.palco {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
}

.palco .quadro {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  height: 100%;
  border-radius: var(--raio-g);
  overflow: hidden;
  background: #0f1736;
}
.palco .quadro img { width: 100%; height: 100%; object-fit: cover; }
.palco .quadro img.fundo { display: none; }
.palco .quadro img.entrar { animation: virar .45s ease-out; }

@keyframes virar {
  from { opacity: 0; transform: scale(1.03); }
  to { opacity: 1; transform: none; }
}

.palco .canto {
  position: absolute;
  top: calc(18px + var(--safe-t));
  display: flex;
  gap: 10px;
  z-index: 2;
}
.palco .canto.esq { left: calc(18px + var(--safe-l)); }
.palco .canto.dir { right: calc(18px + var(--safe-r)); }
.canto .redondo { width: 54px; height: 54px; background: rgba(255, 244, 212, .92); }
.canto .redondo svg { width: 28px; height: 28px; }
.canto .redondo.ligado { background: var(--estrela); }

.numero {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(27, 39, 82, .75);
  color: var(--palha);
  border-radius: 999px;
  padding: 2px 14px 0;
  font-size: 1rem;
  font-weight: 700;
}

.barra {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l));
}

.legenda {
  background: var(--palha);
  border-radius: var(--raio-g);
  padding: 14px 24px 12px;
  min-height: 108px;
  display: grid;
  align-content: center;
  text-align: center;
  box-shadow: inset 0 -5px 0 rgba(240, 169, 28, .25);
}

.legenda .titulo {
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  font-weight: 800;
  color: var(--manto);
  margin-bottom: 4px;
}

.legenda .texto {
  font-size: clamp(1.25rem, 2.6vw, 2rem);
  line-height: 1.35;
  font-weight: 700;
  max-width: 34em;
  margin: 0 auto;
}

.palavra {
  display: inline-block;
  padding: 0 .08em;
  border-radius: 10px;
  transition: color .12s, background-color .12s;
  cursor: pointer;
}
.palavra.lida { color: #8a6a1e; }
.palavra.agora {
  color: var(--noite);
  background: var(--estrela);
  box-shadow: 0 0 0 3px var(--estrela), 0 0 18px 4px rgba(246, 196, 83, .8);
}

.barra .redondo { width: 72px; height: 72px; }
.barra .redondo svg { width: 38px; height: 38px; }

.ouvir {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(27, 39, 82, .35);
  z-index: 3;
}
.ouvir .redondo { width: 110px; height: 110px; background: var(--estrela); }
.ouvir .redondo svg { width: 56px; height: 56px; }

/* páginas finais (lição, versículo, oração) */
.fim .legenda .texto { font-size: clamp(1.35rem, 2.9vw, 2.2rem); }

/* ---------- convite para colorir e galeria ---------- */
.galeria { max-width: 1100px; margin: 0 auto; }
.galeria h1 {
  text-align: center;
  font-size: clamp(2.2rem, 6.5vw, 4rem);
  line-height: 1;
  font-weight: 800;
  color: var(--estrela);
  margin: 6px 0 4px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.galeria p.sub { text-align: center; margin: 0 0 24px; font-size: 1.2rem; }

.desenhos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 20px;
}
.desenho {
  background: var(--branco);
  border-radius: var(--raio-g);
  overflow: hidden;
  box-shadow: var(--sombra);
  text-align: center;
  color: var(--tinta);
}
.desenho:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(15, 20, 48, .35); }
.desenho .mini { position: relative; aspect-ratio: 16 / 9; }
.desenho .mini img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.desenho .mini img.pintura { mix-blend-mode: multiply; }
.desenho .mini img.traco { mix-blend-mode: multiply; }
.desenho span { display: block; padding: 8px 10px 12px; font-size: 1.15rem; font-weight: 800; background: var(--palha); }

/* ---------- tela de pintura ---------- */
.pintar {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--noite);
  overflow: hidden;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  gap: 10px;
}

.pintar .topo h2 {
  margin: 0;
  color: var(--palha);
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: 800;
  text-align: center;
  flex: 1;
}
.pintar .topo .grupo { display: flex; gap: 10px; }
.pintar .topo .redondo { width: 54px; height: 54px; }
.pintar .topo .redondo svg { width: 28px; height: 28px; }

.tela {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}
.folha {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--branco);
  border-radius: var(--raio-p);
  overflow: hidden;
  touch-action: none;
}
.folha canvas, .folha img { position: absolute; inset: 0; width: 100%; height: 100%; }
.folha img { pointer-events: none; mix-blend-mode: multiply; }

.brilho {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}
.brilho i {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px;
  background: var(--estrela);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: brilhar .6s ease-out forwards;
}
@keyframes brilhar {
  from { transform: translate(0, 0) scale(.4); opacity: 1; }
  to { transform: translate(var(--x), var(--y)) scale(1.2) rotate(90deg); opacity: 0; }
}

.ferramentas {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 6px;
  scrollbar-width: none;
}
.ferramentas::-webkit-scrollbar { display: none; }

.cores { display: flex; gap: 10px; }
.cor {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 50%;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), 0 0 0 3px rgba(255, 255, 255, .25);
  transition: transform .12s;
}
.cor.escolhida { transform: scale(1.18); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), 0 0 0 4px var(--palha), 0 0 0 7px var(--estrela); }

.separador { width: 3px; height: 44px; flex: none; border-radius: 3px; background: rgba(255, 244, 212, .2); }

.ferramenta {
  width: 58px;
  height: 58px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255, 244, 212, .14);
  color: var(--palha);
}
.ferramenta svg { width: 32px; height: 32px; }
.ferramenta.ativa { background: var(--palha); color: var(--noite); }

.aviso {
  position: fixed;
  left: 50%;
  bottom: calc(110px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--palha);
  color: var(--noite);
  font-weight: 800;
  font-size: 1.15rem;
  padding: 10px 22px 8px;
  border-radius: 999px;
  box-shadow: var(--sombra);
  z-index: 10;
  animation: aviso 2.4s ease forwards;
}
@keyframes aviso {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}

.confirmar {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 20, 48, .6);
  z-index: 20;
  padding: 20px;
}
.confirmar .caixa {
  background: var(--palha);
  border-radius: var(--raio-g);
  padding: 26px 28px 22px;
  text-align: center;
  max-width: 420px;
}
.confirmar h3 { margin: 0 0 18px; font-size: 1.6rem; line-height: 1.15; }
.confirmar .acoes .botao { min-height: 58px; font-size: 1.25rem; }
.confirmar .acoes .botao.claro { background: #fff; }

/* aviso "vire o celular" (só aparece no celular em pé) */
.girar { display: none; }

/* ---------- celular e tablet em pé ---------- */
@media (orientation: portrait) {
  .leitor { grid-template-rows: auto auto; align-content: center; }
  .legenda .texto, .fim .legenda .texto { font-size: clamp(1.35rem, 3.8vw, 2.2rem); }
  .cores { flex-wrap: wrap; justify-content: center; width: 100%; }
  .cor { width: clamp(40px, 9vw, 60px); height: clamp(40px, 9vw, 60px); }
  .palco { padding-top: calc(80px + var(--safe-t)); }
  .palco .quadro { height: auto; width: 100%; }
  .barra { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; align-content: start; }
  .barra .legenda { grid-column: 1 / -1; grid-row: 1; }
  .barra .anterior { grid-row: 2; justify-self: start; }
  .barra .proxima { grid-row: 2; justify-self: end; }
  .ferramentas { flex-wrap: wrap; justify-content: center; overflow: visible; }
  .folha { height: auto; width: 100%; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .girar {
    position: fixed;
    left: 50%;
    bottom: calc(18px + var(--safe-b));
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 6px;
    border-radius: 999px;
    background: var(--estrela);
    color: var(--noite);
    font-weight: 800;
    font-size: 1.05rem;
    white-space: nowrap;
    box-shadow: var(--sombra);
    pointer-events: none;
    z-index: 15;
    animation: girar-some 6s ease forwards;
  }
  .girar svg { width: 26px; height: 26px; animation: girar-celular 1.6s ease-in-out 2; }
}
@keyframes girar-some {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
@keyframes girar-celular {
  0%, 30% { transform: rotate(0); }
  70%, 100% { transform: rotate(-90deg); }
}

/* telas baixas (celular deitado): a ilustração ocupa a altura toda,
   setas nas laterais e legenda por cima da parte de baixo do desenho */
@media (orientation: landscape) and (max-height: 500px), (orientation: landscape) and (min-aspect-ratio: 17/9), (display-mode: fullscreen) and (orientation: landscape) {
  .leitor { display: block; position: relative; }
  .palco { position: absolute; inset: 0; padding: 0; }
  .palco .quadro {
    height: 100dvh;
    width: 100vw;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
  }
  /* ilustração inteira no centro (sem corte); nas laterais, a mesma cena ampliada e desfocada */
  .palco .quadro img.principal { position: relative; z-index: 1; object-fit: contain; }
  .palco .quadro img.fundo {
    display: block;
    position: absolute;
    inset: 0;
    object-fit: cover;
    filter: blur(22px) brightness(.75) saturate(1.15);
    transform: scale(1.15);
  }
  .palco .quadro .numero { z-index: 2; }
  .barra .redondo { box-shadow: 0 4px 14px rgba(15, 20, 48, .45); }
  .palco .canto { top: calc(10px + var(--safe-t)); }
  .palco .canto.esq { left: calc(10px + var(--safe-l)); }
  .palco .canto.dir { right: calc(10px + var(--safe-r)); }
  .canto .redondo { width: 48px; height: 48px; }
  .numero { top: calc(14px + var(--safe-t)); bottom: auto; }

  .barra {
    position: absolute;
    inset: 0;
    display: block;
    padding: 0;
    pointer-events: none;
    z-index: 4;
  }
  .barra > * { pointer-events: auto; }
  .barra .redondo { position: absolute; top: calc(50% - 30px); width: 60px; height: 60px; }
  .barra .anterior { left: calc(10px + var(--safe-l)); }
  .barra .proxima { right: calc(10px + var(--safe-r)); }
  .barra .redondo svg { width: 32px; height: 32px; }

  .legenda {
    position: absolute;
    left: 50%;
    bottom: calc(8px + var(--safe-b));
    transform: translateX(-50%);
    width: min(calc(100vw - 180px), 640px);
    min-height: 0;
    padding: 6px 18px 4px;
    background: rgba(255, 244, 212, .93);
    box-shadow: 0 6px 24px rgba(15, 20, 48, .35);
  }
  .legenda .titulo { font-size: 1rem; margin-bottom: 0; }
  .legenda .texto, .fim .legenda .texto { font-size: clamp(1.1rem, 2.4vh + .4rem, 1.7rem); line-height: 1.25; }
}

@media (orientation: landscape) and (max-height: 500px) {
  /* pintura: botões em colunas dos lados, desenho com a altura toda */
  .pintar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr;
    gap: 10px;
    padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l));
  }
  .pintar .topo { grid-column: 1; flex-direction: column; justify-content: space-between; }
  .pintar .topo h2 { display: none; }
  .pintar .topo .grupo { flex-direction: column; gap: 8px; }
  .pintar .topo .redondo { width: 48px; height: 48px; }
  .pintar .tela { grid-column: 2; grid-row: 1; }
  .ferramentas {
    grid-column: 3;
    grid-row: 1;
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 2px 4px;
    gap: 8px;
  }
  .ferramentas .separador { width: 44px; height: 3px; }
  .cores { display: grid; grid-template-columns: repeat(2, 40px); gap: 8px; }
  .cor { width: 40px; height: 40px; }
  .ferramenta { width: 48px; height: 48px; }

  /* capa: ilustração à esquerda, título e botão à direita */
  .capa {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    align-items: center;
    column-gap: 22px;
    row-gap: 6px;
  }
  .capa .topo { grid-column: 1 / -1; }
  .capa-img { width: min(100%, calc((100dvh - 120px) * 16 / 9)); min-width: 0; justify-self: end; }
  .capa-titulo h1 { font-size: 2.4rem; }
  .capa-titulo p { font-size: 1rem; }
  .capa .acoes { margin-top: 14px !important; }
  .botao { min-height: 56px; font-size: 1.2rem; padding: 8px 24px 6px; }

  /* estante e galeria: títulos menores, mais desenhos por linha */
  .ceu { padding-top: calc(12px + var(--safe-t)); }
  .estante h1, .galeria h1 { font-size: 2rem; margin: 0 0 2px; }
  .estante p.sub, .galeria p.sub { margin-bottom: 12px; font-size: 1rem; }
  .galeria { position: relative; }
  .galeria .topo { position: absolute; top: 0; left: 0; }
  .desenhos { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .desenho span { font-size: 1rem; padding: 6px 8px 8px; }
  .livros { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .em-breve { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
