:root {
  --vermelho: #B3122E;
  --vermelho-escuro: #8A0D23;
  --verde: #1F5E3B;
  --verde-claro: #2E7D50;
  --dourado: #E8B53D;
  --creme: #FFF8EB;
  --texto: #2B1A12;
  --cinza: #7A6A5E;
  --raio: 16px;
  --seguro-topo: env(safe-area-inset-top, 0px);
  --seguro-base: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--creme);
  color: var(--texto);
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- telas ---------- */
.tela {
  display: none;
  min-height: 100dvh;
  padding: calc(16px + var(--seguro-topo)) 18px calc(24px + var(--seguro-base));
  max-width: 560px;
  margin: 0 auto;
  flex-direction: column;
}
.tela.ativa { display: flex; }
.tela-escura { background: #000; max-width: none; padding: 0; color: #fff; }

/* ---------- topo ---------- */
.topo { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.topo .logo { width: 54px; height: 54px; border-radius: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.topo h1 { margin: 0; font-size: 1.45rem; color: var(--vermelho); line-height: 1.1; }
.topo .sub {
  margin: 2px 0 0; display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--verde); background: var(--dourado); padding: 2px 8px; border-radius: 999px;
}
.topo-simples { justify-content: space-between; }
.titulo-tela { font-size: 1.15rem !important; }

h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--verde); margin: 18px 0 8px; }

/* ---------- faixas ---------- */
.faixa-evento, .faixa-instalar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-radius: var(--raio); padding: 12px 14px; margin-bottom: 6px;
}
.faixa-evento { background: var(--verde); color: #fff; }
.faixa-evento .rotulo { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--dourado); }
.faixa-evento .btn-texto { color: #fff; }
.faixa-instalar { background: #fff; border: 1px dashed var(--dourado); font-size: .92rem; }

/* ---------- formatos ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 2px solid var(--verde); background: #fff; color: var(--verde);
  border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: .92rem;
}
.chip.sel { background: var(--verde); color: #fff; }
.chip:disabled { opacity: .45; }

/* ---------- molduras ---------- */
.grade-molduras { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.moldura-item {
  position: relative; border: 3px solid transparent; border-radius: 12px; padding: 0; overflow: hidden;
  background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 50% / 16px 16px;
  aspect-ratio: var(--proporcao, 9/16);
}
.moldura-item img { width: 100%; height: 100%; object-fit: fill; display: block; }
.moldura-item.sel { border-color: var(--vermelho); box-shadow: 0 0 0 2px var(--dourado); }
.moldura-item .nome {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: .7rem; background: rgba(0,0,0,.55); color: #fff; padding: 3px;
  text-align: center;
}
.moldura-item .apagar {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: .8rem; line-height: 24px; padding: 0;
}
.moldura-item.nova, .moldura-item.nenhuma {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 4px;
  background: #fff; border: 2px dashed var(--dourado); color: var(--vermelho); font-weight: 600; font-size: .8rem; text-align: center;
}
.moldura-item.nova span:first-child { font-size: 1.6rem; line-height: 1; }
.moldura-item.nenhuma.sel { border: 3px solid var(--vermelho); }
.moldura-item:disabled { opacity: .4; }

/* ---------- botões ---------- */
.acoes-foto { margin-top: auto; padding-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  border: 0; border-radius: var(--raio); padding: 15px 14px; font-weight: 700; font-size: 1rem;
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn-principal { background: var(--vermelho); color: #fff; box-shadow: 0 4px 0 var(--vermelho-escuro); }
.btn-principal:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--vermelho-escuro); }
.btn-secundario { background: #fff; color: var(--verde); border: 2px solid var(--verde); font-size: .93rem; }
.btn-texto { background: none; border: 0; color: var(--vermelho); font-weight: 600; padding: 6px 4px; }
.btn .ico { font-size: 1.3rem; }

.rodape { display: flex; justify-content: space-between; margin-top: 18px; }

/* ---------- câmera ---------- */
#tela-camera.ativa { display: flex; }
#tela-camera { flex-direction: column; height: 100dvh; }
.camera-area {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0;
  padding: calc(8px + var(--seguro-topo)) 8px 8px;
  container-type: size;
}
.camera-quadro {
  position: relative; overflow: hidden; border-radius: 10px; background: #111;
  aspect-ratio: var(--proporcao, 9/16);
  width: min(100cqw, calc(100cqh * var(--r, .5625)));
}
.aviso-girar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); white-space: nowrap;
  background: rgba(0,0,0,.65); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: .9rem; font-weight: 600;
}
/* celular deitado: controles na lateral */
@media (orientation: landscape) and (max-height: 600px) {
  #tela-camera.ativa { flex-direction: row; }
  #tela-camera .camera-area { padding: 8px 0 8px calc(8px + env(safe-area-inset-left, 0px)); }
  #tela-camera .camera-controles {
    grid-template-columns: none; grid-template-rows: 1fr auto 1fr; padding: 12px calc(14px + env(safe-area-inset-right, 0px)) 12px 14px;
  }
  #tela-camera .coluna-controles { flex-direction: column; }
}
.camera-quadro video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.camera-quadro video.espelho { transform: scaleX(-1); }
.camera-quadro video.espelho-v { transform: scaleY(-1); }
.camera-quadro img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.contagem {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 7rem; font-weight: 800; color: #fff; text-shadow: 0 4px 18px rgba(0,0,0,.6);
}
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .35s; }
.flash.on { opacity: 1; transition: none; }
.camera-controles {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; justify-items: center; gap: 10px;
  padding: 14px 12px calc(18px + var(--seguro-base));
}
.coluna-controles { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn-redondo {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 1.2rem;
}
.btn-timer { width: auto; padding: 0 14px; border-radius: 26px; font-size: .95rem; }
.btn-disparo {
  width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; background: var(--vermelho);
  box-shadow: 0 0 0 4px var(--dourado);
}
.btn-disparo:active { transform: scale(.94); }
.camera-erro { text-align: center; padding: 0 24px 20px; color: #ffd; }

/* ---------- resultado ---------- */
.resultado-area { display: flex; justify-content: center; }
#canvas-final {
  max-width: 100%; max-height: 58dvh; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  touch-action: none; background: #ddd;
}
.dica { text-align: center; color: var(--cinza); font-size: .88rem; margin: 10px 0 4px; }
.dica.pequena { font-size: .8rem; }
.zoom { display: flex; align-items: center; gap: 10px; font-size: .88rem; color: var(--cinza); margin: 4px 0 12px; }
.zoom input { flex: 1; accent-color: var(--vermelho); }
.acoes-resultado { display: flex; flex-direction: column; gap: 10px; }

/* ---------- evento ---------- */
.explica { margin: 0 0 8px; color: var(--cinza); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label, .bloco-importar label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .92rem; }
.form small { font-weight: 400; color: var(--cinza); }
input[type=text], input[type=url], select, textarea {
  font: inherit; font-weight: 400; padding: 12px; border-radius: 12px; border: 2px solid #E3D6C3; background: #fff; color: var(--texto);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--verde); }
.bloco-evento { background: #fff; border-radius: var(--raio); padding: 14px; margin-top: 16px; border: 2px solid var(--dourado); }
.bloco-evento h3 { margin-top: 0; }
.bloco-evento p { margin: 0 0 10px; font-size: .92rem; }
.bloco-importar { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.bloco-importar h3 { margin-bottom: 0; }
.qr { display: flex; justify-content: center; margin: 6px 0 12px; }
.qr img { width: 220px; height: 220px; image-rendering: pixelated; }

/* ---------- instalar ---------- */
#tela-instalar ol { padding-left: 22px; line-height: 1.6; }
.aviso-ok { background: #E6F2EA; color: var(--verde); border-radius: var(--raio); padding: 12px 14px; font-weight: 600; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--seguro-base)); transform: translate(-50%, 30px);
  background: var(--texto); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw; text-align: center; z-index: 10;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- cartões da tela inicial ---------- */
.cartao { background: #fff; border-radius: 22px; padding: 16px; margin-top: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.cartao-evento { border: 2px solid var(--vermelho); }
.cartao-titulo { display: flex; align-items: center; gap: 8px; }
.cartao-ico { font-size: 1.4rem; }
.h-cartao { flex: 1; margin: 0; font-size: 1.25rem; color: var(--vermelho-escuro); }
.cartao .explica { margin: 6px 0 10px; font-size: .92rem; }
.cartao .acoes-foto { margin-top: 0; }
.mini-rotulo { margin: 8px 0 6px; font-size: .8rem; font-weight: 600; color: var(--cinza); }

.lista-eventos { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.evento-item {
  display: flex; align-items: center; gap: 10px; background: var(--creme); border-radius: 14px; padding: 8px 8px 8px 8px;
}
.evento-item .miniatura {
  width: 40px; flex: none; border-radius: 6px; overflow: hidden; background: #d9e6dd;
  aspect-ratio: var(--proporcao, 9/16);
}
.evento-item .miniatura img { width: 100%; height: 100%; object-fit: fill; display: block; }
.evento-item .textos { flex: 1; min-width: 0; }
.evento-item .nome { font-weight: 700; color: var(--vermelho-escuro); line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.evento-item .detalhe { font-size: .78rem; color: var(--cinza); }
.evento-item .btn-icone { background: none; border: 0; font-size: 1rem; padding: 6px 2px; color: var(--cinza); }
.btn-iniciar {
  border: 0; border-radius: 12px; background: var(--vermelho); color: #fff; font-weight: 700; padding: 11px 14px; white-space: nowrap;
}
.evento-item.grande { flex-wrap: wrap; background: #fff; border: 1px solid #EFE3D0; padding: 12px; }
.evento-item.grande .acoes { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; width: 100%; }
.evento-item.grande .acoes .btn { padding: 11px 8px; font-size: .9rem; }

.btn-dourado { background: var(--dourado); color: var(--vermelho-escuro); }

/* ---------- configurar evento ---------- */
.campo { display: flex; flex-direction: column; gap: 8px; }
.campo-rotulo { font-weight: 600; font-size: .92rem; }
.campo small { color: var(--cinza); font-size: .8rem; }
.segmentado { display: flex; background: #fff; border: 2px solid var(--verde); border-radius: 12px; overflow: hidden; }
.segmentado button { flex: 1; border: 0; background: none; padding: 10px 4px; font-weight: 600; color: var(--verde); font-size: .88rem; }
.segmentado button + button { border-left: 1px solid #cfe0d5; }
.segmentado button.sel { background: var(--verde); color: #fff; }
#ev-molduras .moldura-item { width: 100%; }
.btn-excluir { display: block; margin: 22px auto 0; color: #B42318; }

/* ---------- evento em andamento ---------- */
.tela-evento-ativo { background: var(--verde); color: #fff; max-width: none; }
.tela-evento-ativo > * { width: 100%; max-width: 560px; margin-left: auto; margin-right: auto; }
.tela-evento-ativo .btn-texto { color: #fff; }
.evento-cabecalho { text-align: center; }
.evento-cabecalho .rotulo { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--dourado); font-weight: 700; }
.evento-cabecalho h1 { margin: 4px 0; font-size: 1.6rem; }
.evento-cabecalho p { margin: 0; opacity: .85; font-size: .9rem; }
.evento-previa-area { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px 0; min-height: 0; }
.evento-previa {
  width: min(100%, calc(42dvh * var(--r, .5625))); aspect-ratio: var(--proporcao, 9/16); border-radius: 12px; overflow: hidden;
  background: repeating-conic-gradient(#e9efe9 0 25%, #fff 0 50%) 50% / 18px 18px; box-shadow: 0 8px 28px rgba(0,0,0,.3);
}
.evento-previa img { width: 100%; height: 100%; object-fit: fill; display: block; }
.btn-grande { padding: 20px; font-size: 1.2rem; }
.btn-claro { background: transparent; color: #fff; border-color: rgba(255,255,255,.7); }

.form > label, .bloco-importar > label { display: block; }
.form > label input, .form > label textarea, .bloco-importar > label input { display: block; width: 100%; margin-top: 6px; }

.grade-molduras.paisagem { grid-template-columns: repeat(2, 1fr); }
.evento-item .miniatura.deitado { width: 64px; }

/* ---------- prompts ---------- */
.cartao-link {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 2px solid var(--dourado);
  font: inherit; color: var(--vermelho-escuro);
}
.cartao-link-textos { flex: 1; display: flex; flex-direction: column; }
.cartao-link-textos small { color: var(--cinza); font-size: .85rem; }
.cartao-link .seta { font-size: 1.6rem; color: var(--vermelho); }
.btn-pequeno { padding: 10px; font-size: .88rem; margin-top: 4px; }
a.btn { text-decoration: none; }
.prompt-texto {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; font-size: .82rem; line-height: 1.45;
  background: #fff; color: var(--vermelho-escuro); border-radius: 14px; padding: 14px; border: 1px solid #EFE3D0;
  max-height: 46dvh; overflow: auto; user-select: text; -webkit-user-select: text;
}
.aviso-dica { background: #FBF0D2; border-radius: 12px; padding: 12px 14px; }
.aviso-dica strong { color: var(--vermelho-escuro); font-size: .92rem; }
.aviso-dica p { margin: 4px 0 0; font-size: .85rem; color: var(--cinza); }
#tela-prompts .form h3 { margin: 8px 0 0; }

/* ---------- evento: em pé / deitada ---------- */
.explica.pequena { font-size: .88rem; margin: 0; }
.bloco-orient { background: #fff; border: 2px solid var(--verde); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bloco-orient.desligado { border-color: #E3D6C3; background: transparent; }
.bloco-orient .campo { gap: 6px; }
.form .liga { display: flex; flex-direction: row; align-items: center; gap: 12px; cursor: pointer; text-align: left; }
.liga input { width: 24px; height: 24px; accent-color: var(--verde); flex: none; margin: 0; }
.liga-texto { display: flex; flex-direction: column; }
.liga-texto strong { color: var(--verde); font-size: 1rem; }
.liga-texto small { color: var(--cinza); font-weight: 400; }
.segmentado-claro { margin: 14px auto 0; border-color: rgba(255,255,255,.75); background: transparent; max-width: 320px; }
.segmentado-claro button { color: #fff; }
.segmentado-claro button + button { border-left-color: rgba(255,255,255,.4); }
.segmentado-claro button.sel { background: #fff; color: var(--verde); }
.evento-dica { text-align: center; font-size: .82rem; opacity: .85; margin: 8px 0 0; }

/* ---------- menu enviar moldura ---------- */
.folha-fundo { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.folha {
  width: 100%; max-width: 560px; background: var(--creme); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + var(--seguro-base)); display: flex; flex-direction: column; gap: 10px;
  animation: subir .2s ease-out;
}
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
.folha h3 { margin: 0 0 4px; }
.folha-drive { background: #fff; border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.folha-drive label { display: block; font-weight: 600; font-size: .92rem; }
.folha-drive input { display: block; width: 100%; margin-top: 6px; }
.folha-drive small { color: var(--cinza); font-size: .8rem; }
.folha .btn-texto { align-self: center; }

/* ---------- câmera com moldura deitada e tela travada em pé ----------
   O celular está deitado, mas a tela continua em pé: o vídeo já aparece certo,
   então só a moldura (e os textos) giram 90°. */
.camera-quadro.girado { container-type: size; }
.camera-quadro.girado #camera-moldura {
  inset: auto; left: 50%; top: 50%; width: 100cqh; height: 100cqw;
  transform: translate(-50%, -50%) rotate(var(--giro, 90deg));
}
.camera-quadro.girado .contagem { transform: rotate(var(--giro, 90deg)); }
.aviso-deitado {
  position: absolute; left: 50%; top: 50%; white-space: nowrap;
  transform: translate(-50%, -50%) rotate(var(--giro, 90deg));
  background: rgba(0,0,0,.65); color: #fff; padding: 10px 16px; border-radius: 999px; font-weight: 700;
}
.coluna-controles .btn-redondo { width: 46px; height: 46px; font-size: 1.05rem; }
.btn-inverter { position: absolute; left: 10px; bottom: 10px; width: 42px; height: 42px; background: rgba(0,0,0,.55); font-size: 1.1rem; }

/* ---------- "Ver mais": imagem inteira da câmera, fundo desfocado ---------- */
#video-fundo { display: none; }
.camera-quadro.ver-mais #video-fundo {
  display: block; position: absolute; inset: -8%; width: 116%; height: 116%; object-fit: cover;
  filter: blur(22px) brightness(.75);
}
.camera-quadro.ver-mais #video { object-fit: contain; }
.btn-ver-mais {
  position: absolute; right: 10px; top: 10px; border: 0; border-radius: 999px;
  background: rgba(0,0,0,.6); color: #fff; font-weight: 700; font-size: .85rem; padding: 9px 13px;
}
.btn-ver-mais, .btn-inverter { z-index: 2; }
.btn-desvirar {
  position: absolute; left: 10px; top: 10px; z-index: 2; border: 0; border-radius: 999px;
  background: rgba(0,0,0,.6); color: #fff; font-weight: 700; font-size: .85rem; padding: 9px 13px;
}
.btn-desvirar.ligado { background: var(--dourado); color: var(--vermelho-escuro); }
.diag { position: fixed; left: 4px; top: 4px; right: 4px; z-index: 30; margin: 0; padding: 6px 8px; background: rgba(0,0,0,.75); color: #9f9; font: 11px/1.35 monospace; white-space: pre-wrap; pointer-events: none; border-radius: 6px; }
