* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #120c1c; }
body {
  font-family: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===================== CENA ===================== */
#cena { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.nuvem, .passaro {
  animation-name: deriva;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes deriva {
  from { transform: translateX(-350px); }
  to   { transform: translateX(1900px); }
}
.asa { animation: bater .32s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes bater { to { transform: scaleY(-.5); } }
.bandeira { animation: tremular 1.1s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: left center; }
@keyframes tremular {
  from { transform: scaleX(1) skewY(-3deg); }
  to   { transform: scaleX(.86) skewY(4deg); }
}

.balao text {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-weight: 600;
  font-size: 28px;
  fill: #4b2e39;
}

/* ===================== HUD ===================== */
#hud {
  position: fixed; left: 0; right: 0; bottom: 8vh; z-index: 5;
  display: flex; justify-content: center;
  pointer-events: none;
}
#btnResgatar {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: .45em;
  font: 700 clamp(22px, 3.2vw, 38px)/1 "Fredoka", "Trebuchet MS", sans-serif;
  letter-spacing: .02em;
  color: #6a3500;
  padding: .62em 1.7em .68em;
  border: 4px solid #fff4c9;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe17a 0%, #ffc531 55%, #f5a316 100%);
  box-shadow: 0 7px 0 #c47a06, 0 16px 34px rgba(40, 20, 60, .35), inset 0 2px 0 rgba(255, 255, 255, .7);
  cursor: pointer;
  opacity: 0;
  transform: translateY(40px) scale(.85);
  transition: opacity .5s ease, transform .55s cubic-bezier(.2, 1.6, .4, 1);
}
#btnResgatar:disabled { pointer-events: none; }
#btnResgatar svg { width: 1.05em; height: 1.05em; fill: currentColor; }
#btnResgatar.visivel { opacity: 1; transform: none; animation: pulsar 1.8s ease-in-out .6s infinite; }
@keyframes pulsar { 50% { scale: 1.06; } }
#btnResgatar:hover { filter: brightness(1.06); }
#btnResgatar:active {
  translate: 0 5px;
  box-shadow: 0 2px 0 #c47a06, 0 8px 18px rgba(40, 20, 60, .3), inset 0 2px 0 rgba(255, 255, 255, .7);
}
#btnResgatar:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }

#veu { position: fixed; inset: 0; z-index: 30; background: #120c1c; pointer-events: none; transition: opacity 1.8s ease; }
#flash { position: fixed; inset: 0; z-index: 25; background: #fffaf0; opacity: 0; pointer-events: none; }

/* ===================== HISTÓRIA ===================== */
#historia {
  position: fixed; inset: 0; z-index: 10; overflow: hidden;
  background: #140e22; color: #fff7e6;
  opacity: 0; visibility: hidden;
  transition: opacity 1s ease, visibility 0s 1s;
}
#historia.ativo { opacity: 1; visibility: visible; transition: opacity 1s ease; }

#hFundo {
  position: absolute; inset: -80px;
  background: radial-gradient(ellipse at center, #4a3366 0%, #140e22 75%) center / cover no-repeat;
  filter: blur(30px) brightness(.5) saturate(1.2);
}

#hQuadro {
  position: absolute; top: 8vh; bottom: 22vh; left: 4vw; right: 4vw;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .45s ease, transform .45s ease;
}
#hQuadro.saindo { opacity: 0; transform: scale(.985); }

.moldura {
  position: relative; overflow: hidden; line-height: 0;
  border: 6px solid #fff6e0; border-radius: 12px;
  background: #fff6e0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.moldura img { display: block; max-width: calc(92vw - 12px); max-height: calc(70vh - 12px); }
.moldura img.kb { animation: kenburns 18s ease-out both; }
@keyframes kenburns {
  from { transform: scale(1); }
  to   { transform: scale(1.08) translate(-1.2%, -1%); }
}

.placeholder {
  width: min(84vw, 124vh); aspect-ratio: 16 / 9; max-height: 70vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35em;
  border: 3px dashed #c9a96e; border-radius: 14px;
  background: radial-gradient(ellipse at 30% 20%, #fffaf0, #f3e3c3 70%, #e8d2a8);
  color: #8a6534;
  font-family: "Lora", Georgia, serif;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.placeholder svg { width: clamp(40px, 6vw, 80px); height: auto; fill: currentColor; opacity: .55; }
.placeholder strong { font-size: clamp(24px, 3.4vw, 46px); font-weight: 500; font-style: italic; }
.placeholder small { font-family: "Fredoka", sans-serif; font-size: clamp(14px, 1.5vw, 20px); opacity: .75; }

#hTexto {
  position: absolute; left: 50%; bottom: 5vh; transform: translateX(-50%);
  width: min(1100px, 88vw); min-height: 3.2em;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-family: "Lora", Georgia, serif; font-weight: 500;
  font-size: clamp(18px, 2.3vw, 31px); line-height: 1.45;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .75);
  transition: opacity .45s ease;
}
#hTexto.saindo { opacity: 0; }

#hPontos {
  position: absolute; top: 3vh; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px;
}
#hPontos span {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255, 246, 224, .28);
  transition: background .4s, transform .4s;
}
#hPontos span.feito { background: rgba(255, 214, 102, .6); }
#hPontos span.atual { background: #ffd666; transform: scale(1.35); }

.controles {
  position: absolute; top: 2vh; right: 2vw;
  display: flex; gap: 8px;
  opacity: .5; transition: opacity .3s;
}
.controles:hover, .controles:focus-within { opacity: 1; }
.controles button {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid rgba(255, 246, 224, .5);
  background: rgba(20, 14, 34, .55); color: #fff6e0;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.controles button:hover { background: rgba(255, 214, 102, .25); }
.controles button:active { transform: scale(.92); }
.controles svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- caderno de esboços (cenas desenhadas) ---------- */
#hPalco { position: absolute; inset: 0; overflow: hidden; background: #1c140b; }
.folha {
  position: absolute; inset: -2%;
  background-size: cover; background-position: center;
  opacity: 0;
  transition: opacity 1.4s ease;
  animation: camera var(--dur, 14s) linear both;
  will-change: transform, opacity;
}
.folha.visivel { opacity: 1; }
@keyframes camera { from { transform: var(--de); } to { transform: var(--para); } }
.folha svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.folha .cAquarela { mix-blend-mode: multiply; animation: aparecer 2.6s ease var(--aq, 2s) both; }
.folha .tinta { fill: none; stroke: #3a2716; stroke-opacity: .88; stroke-linecap: round; stroke-linejoin: round; }
.folha .tinta * { stroke-width: calc(2.3px * var(--k, 1)); }
.folha .tinta .f { stroke-width: calc(1.35px * var(--k, 1)); }
.folha .tinta .g { stroke-width: calc(3.4px * var(--k, 1)); }
.folha .tinta .verm { stroke: #a33a2e; stroke-width: calc(3.2px * var(--k, 1)); stroke-opacity: .9; }
.folha .tinta .ponto { fill: #3a2716; stroke: none; }
.folha .tinta .hachura { stroke: none; }
.folha .tinta g, .folha .tinta clipPath { stroke-width: inherit; }
.folha .rotulo {
  fill: #3a2716; stroke: none;
  font-family: "IM Fell English", "Lora", Georgia, serif; font-style: italic;
}
.folha .caligrafia { fill: #3a2716; stroke: none; font-family: "Great Vibes", "Lora", cursive; }
@keyframes desenhar { to { stroke-dashoffset: 0; } }
@keyframes aparecer { from { opacity: 0; } }
#historia.pausado .folha, #historia.pausado .folha * { animation-play-state: paused !important; }

#hVinheta {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(0,0,0,0) 52%, rgba(46, 26, 8, .5) 88%, rgba(28, 16, 4, .82) 100%),
    linear-gradient(to top, rgba(20, 12, 4, .62) 0%, rgba(20, 12, 4, 0) 26%);
  opacity: 0; transition: opacity 1s;
}
#historia.comPapel #hVinheta { opacity: 1; }
#historia.comPapel #hTexto { font-style: italic; color: #fff4dc; text-shadow: 0 2px 6px rgba(0,0,0,.9), 0 0 22px rgba(0,0,0,.6); }
#historia.semLegenda #hTexto { opacity: 0 !important; }
.controles button.desligado { opacity: .45; }

/* ===================== FIM ===================== */
#fim {
  position: fixed; inset: 0; z-index: 12;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4vh;
  background: radial-gradient(ellipse at 50% 40%, #3b2a5c 0%, #1a1230 60%, #0e0a1a 100%);
  color: #ffe7a3;
  opacity: 0; visibility: hidden;
  transition: opacity 1.6s ease, visibility 0s 1.6s;
}
#fim.ativo { opacity: 1; visibility: visible; transition: opacity 1.6s ease; }
#fim h1 {
  font-family: "Great Vibes", "Lora", cursive; font-weight: 400;
  font-size: clamp(90px, 16vw, 220px); line-height: 1;
  text-shadow: 0 0 30px rgba(255, 214, 102, .45);
}
#bDeNovo {
  font: 600 clamp(18px, 2vw, 24px) "Fredoka", sans-serif;
  color: #3b2a5c; background: #ffe7a3;
  border: 0; border-radius: 999px; padding: .7em 1.8em;
  cursor: pointer; box-shadow: 0 6px 0 #c9a24a;
}
#bDeNovo:active { translate: 0 4px; box-shadow: 0 2px 0 #c9a24a; }

/* ===================== CELULAR EM PÉ ===================== */
#girar {
  position: fixed; inset: 0; z-index: 50;
  display: none; flex-direction: column; gap: 18px; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: #1a1230; color: #ffe7a3;
  font: 600 22px "Fredoka", sans-serif;
}
#girar svg { width: 64px; fill: currentColor; animation: girar 2s ease-in-out infinite; }
@keyframes girar { 50%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 600px) {
  #girar { display: flex; }
}
#fim .assinatura {
  margin-top: -3vh;
  font-family: "Lora", Georgia, serif; font-style: italic;
  font-size: clamp(22px, 2.6vw, 34px); letter-spacing: .08em;
  color: #f3d9a0; opacity: .85;
}
