/*
  Mockups da interface e cenas animadas.

  Como uma cena funciona (nível 3 "vitrine", 07-movimento.md):
    - o HTML descreve o ESTADO FINAL: sem JS, ou com movimento reduzido, a cena
      já aparece pronta;
    - com JS, cenas.js põe `.is-play` no elemento `.cena` quando ele entra na
      tela; os filhos `.a` animam do estado inicial até o final e param;
    - "Ver de novo" tira e recoloca `.is-play`;
    - só `transform` e `opacity` (e stroke-dashoffset em SVG);
    - a ordem e o ritmo vêm das classes .t1 a .t24 (passos de 300ms).
*/

/* ------------------------------------------------------ primitivas de UI == */
.mk-cartao {
  position: relative; display: grid; gap: var(--space-3); width: 100%; max-width: 440px; margin: 0 auto;
  padding: var(--space-5, 20px); border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface-raised); box-shadow: var(--shadow-lg);
}
.mk-topo { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.mk-topo strong { font-weight: 600; }
.mk-item, .mk-linha {
  position: relative; display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg);
  font-size: 15px; line-height: 20px;
}
.mk-item > div, .mk-linha > span:not(.am-badge):not(.troca) { flex: 1; min-width: 0; }
.mk-item strong, .mk-qr strong { display: block; font-weight: 600; }
.mk-item small, .mk-linha small, .mk-qr small { display: block; }
.mk-linha > .i { color: var(--text-secondary); }
.mk-ico { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--accent-subtle); color: var(--accent-text); }
.mk-ico--ok { background: var(--success-bg); color: var(--success-text); }
.mk-qr { position: relative; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius-md); background: var(--bg-muted); overflow: hidden; }
.mk-qr--grande { justify-content: center; padding: var(--space-6); color: var(--text); }
.mk-botao { display: grid; place-items: center; height: 44px; border-radius: var(--radius-md); background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 15px; }
.mk-texto { font-size: 15px; }
.mk-voto { display: grid; grid-template-columns: 84px 1fr 40px; align-items: center; gap: var(--space-3); font-size: 14px; color: var(--text-secondary); }
.mk-voto strong { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.mk-barra { height: 8px; border-radius: var(--radius-full); background: var(--bg-muted); overflow: hidden; }
.mk-barra i { display: block; height: 100%; border-radius: var(--radius-full); transform-origin: left; }
.mk-barra__a { width: 76%; background: var(--success-solid); }
.mk-barra__b { width: 18%; background: var(--text-tertiary); }
.mk-barra__c { width: 6%; background: var(--text-tertiary); }
.mk-barra__72 { width: 72%; background: var(--accent); }
.mk-passos { display: grid; grid-template-columns: repeat(8, 1fr); gap: var(--space-1); }
.mk-passo { height: 6px; border-radius: var(--radius-full); background: var(--bg-muted); transform-origin: left; }
.mk-passo--ok { background: var(--success-solid); }
.mk-passo--atual { background: var(--accent); }
.mk-bolha { max-width: 90%; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); background: var(--bg-muted); color: var(--text); font-size: 15px; line-height: 22px; }
.mk-bolha--eu { justify-self: end; background: var(--accent-subtle); color: var(--accent-text); }
.mk-fonte { display: inline-flex; align-items: center; gap: var(--space-1); justify-self: start; padding: 2px var(--space-2); border-radius: var(--radius-xs); background: var(--bg-muted); }
.av-fila { display: flex; gap: var(--space-1); flex-wrap: wrap; }
.av { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-subtle); color: var(--accent-text); font-size: 12px; font-weight: 600; }
.av--ok { background: var(--success-bg); color: var(--success-text); }
.selo {
  position: absolute; right: 36px; bottom: 30px; display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4); border: 2px solid var(--success-solid); border-radius: var(--radius-md);
  color: var(--success-text); font-weight: 700; font-size: 14px; letter-spacing: .04em; background: var(--surface-raised);
  transform: rotate(-6deg);
}
.mk-etiqueta { position: relative; display: grid; gap: 6px; padding: var(--space-3); border-radius: var(--radius-md); background: var(--bg-muted); overflow: hidden; }
.mk-etiqueta i { display: block; height: 6px; border-radius: 3px; background: var(--border-strong); opacity: .5; }
.mk-etiqueta i:nth-child(1) { width: 60%; } .mk-etiqueta i:nth-child(2) { width: 85%; } .mk-etiqueta i:nth-child(3) { width: 40%; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.scan { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--accent); box-shadow: 0 0 12px var(--accent); opacity: 0; }
.ok-marca { position: absolute; top: 50%; left: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; display: grid; place-items: center; }
.ok-marca svg { width: 64px; height: 64px; fill: var(--success-bg); stroke: var(--success-solid); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.troca { position: relative; display: inline-grid; flex: none; }
.troca > * { grid-area: 1 / 1; justify-self: end; }
.troca > small { justify-self: start; }

/* Botão "Ver de novo" fica FORA do mockup (que é aria-hidden). */
.arte { position: relative; display: grid; gap: var(--space-3); justify-items: center; }
.arte .replay { opacity: .8; }
.arte .replay:hover { opacity: 1; }
.replay[hidden] { display: none; }

/* --------------------------------------------------------------- celular == */
.celular {
  position: relative; width: min(100%, 280px); padding: 10px;
  background: var(--neutral-800); border-radius: 36px; box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, .08);
}
.celular__tela { display: flex; flex-direction: column; gap: var(--space-2); min-height: 470px; padding: var(--space-4) var(--space-3); background: var(--bg-subtle); border-radius: 28px; overflow: hidden; }
.celular .mk-item { padding: var(--space-2) var(--space-3); font-size: 14px; }
.celular .mk-topo { font-size: 15px; }
.notif {
  position: absolute; left: 14px; right: 14px; top: 18px; z-index: 3; display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3); border-radius: var(--radius-md); background: var(--surface-raised); box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 17px; opacity: 0; pointer-events: none;
}
.notif .i { color: var(--accent-text); }
.notif strong { display: block; font-weight: 600; }

/* ------------------------------------------------------------ palco do hub == */
.palco { position: relative; width: 100%; max-width: 560px; margin: 0 auto; aspect-ratio: 1 / 1.02; }
.palco .celular { position: absolute; right: 0; top: 0; width: 54%; min-width: 250px; }
.celular .mk-item .mk-ico { display: none; }
.palco__linhas { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
/* Sem vector-effect: com ele o tracejado seria medido em pixels de tela e a linha
   (pathLength=1, dasharray=1) viraria pontilhado. O viewBox 100x100 escala quase 1:1. */
.palco__linhas path { stroke: var(--accent); stroke-width: .4; stroke-dasharray: 1; stroke-linecap: round; fill: none; opacity: .85; }
.papel {
  position: absolute; z-index: 2; display: flex; align-items: center; gap: var(--space-3); max-width: 205px;
  padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface-raised); box-shadow: var(--shadow-lg); font-size: 14px; line-height: 18px;
}
.papel strong { display: block; font-weight: 600; }
.papel .i { color: var(--accent-text); }
.papel .troca { display: grid; }
.papel .troca > * { justify-self: start; }
/* O celular fica à direita e os três papéis empilhados à esquerda, ligados por linhas. */
.papel--portaria { left: 0; top: 6%; }
.papel--morador { left: 0; top: 38%; }
.papel--sindico { left: 0; bottom: 8%; }
@media (max-width: 639px) {
  /* No celular os papéis ficam numa faixa acima do aparelho, sem linhas. */
  .palco { max-width: 380px; aspect-ratio: auto; min-height: 570px; }
  .palco .celular { left: 50%; right: auto; top: 68px; transform: translateX(-50%); width: 76%; min-width: 0; }
  .palco__linhas { display: none; }
  .papel { max-width: 172px; padding: var(--space-2) var(--space-3); font-size: 12px; line-height: 16px; }
  .papel--portaria { left: 0; top: 0; }
  .papel--morador { left: auto; right: 0; top: 0; bottom: auto; }
  .papel--sindico { display: none; }
}

/* =================================================== o motor das cenas == */
/* Antes de tocar (e só com JS), tudo que anima fica escondido. */
.js .cena:not(.is-play):not(.is-fim) .a { opacity: 0; }

.t1  { --d: 300ms; }  .t2  { --d: 600ms; }  .t3  { --d: 900ms; }  .t4  { --d: 1200ms; }
.t5  { --d: 1500ms; } .t6  { --d: 1800ms; } .t7  { --d: 2100ms; } .t8  { --d: 2400ms; }
.t9  { --d: 2700ms; } .t10 { --d: 3000ms; } .t11 { --d: 3300ms; } .t12 { --d: 3600ms; }
.t13 { --d: 3900ms; } .t14 { --d: 4200ms; } .t15 { --d: 4500ms; } .t16 { --d: 4800ms; }
.t17 { --d: 5100ms; } .t18 { --d: 5400ms; } .t19 { --d: 5700ms; } .t20 { --d: 6000ms; }

.is-play .a-sobe    { animation: a-sobe var(--duration-base) var(--ease-enter) var(--d, 0ms) backwards; }
.is-play .a-esq     { animation: a-esq var(--duration-base) var(--ease-enter) var(--d, 0ms) backwards; }
.is-play .a-dir     { animation: a-dir var(--duration-base) var(--ease-enter) var(--d, 0ms) backwards; }
.is-play .a-desce   { animation: a-desce var(--duration-base) var(--ease-enter) var(--d, 0ms) backwards; }
.is-play .a-pop     { animation: a-pop var(--duration-spring) var(--ease-spring-lively) var(--d, 0ms) backwards; }
.is-play .a-cresce  { animation: a-cresce 700ms var(--ease-enter) var(--d, 0ms) backwards; }
.is-play .a-lento   { animation: a-cresce 1200ms var(--ease-standard) var(--d, 0ms) backwards; }
.is-play .a-desenha { animation: a-desenha 600ms var(--ease-standard) var(--d, 0ms) backwards; }
.is-play .a-flash   { animation: a-flash 420ms linear var(--d, 0ms) backwards; }
.is-play .a-scan    { animation: a-scan 900ms var(--ease-standard) var(--d, 0ms) backwards; }
.is-play .a-notif   { animation: a-notif 2400ms var(--ease-enter) var(--d, 0ms) backwards; }
/* Troca de estado: "antes" visível até --d e depois some; "depois" já é o estado final. */
.sw-ini { opacity: 0; }
.is-play .sw-ini { animation: a-ini var(--d, 0ms) linear both; }
.is-play .a-marca path { stroke-dasharray: 1; animation: a-desenha var(--duration-base) var(--ease-standard) calc(var(--d, 0ms) + 200ms) backwards; }

@keyframes a-sobe    { from { opacity: 0; transform: translateY(12px); } }
@keyframes a-esq     { from { opacity: 0; transform: translateX(-16px); } }
@keyframes a-dir     { from { opacity: 0; transform: translateX(16px); } }
@keyframes a-desce   { from { opacity: 0; transform: translateY(-14px); } }
@keyframes a-pop     { from { opacity: 0; transform: scale(.6); } }
@keyframes a-cresce  { from { transform: scaleX(0); } }
@keyframes a-desenha { from { stroke-dashoffset: 1; } }
@keyframes a-flash   { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes a-scan    { 0% { opacity: 1; transform: translateY(0); } 90% { opacity: 1; } 100% { opacity: 0; transform: translateY(var(--scan-h, 120px)); } }
@keyframes a-notif   { 0% { opacity: 0; transform: translateY(-14px); } 12% { opacity: 1; transform: none; } 78% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-8px); } }
@keyframes a-ini     { 0%, 99% { opacity: 1; } 100% { opacity: 0; } }
.scan { --scan-h: 112px; }

/* Impressão: cenas no estado final, sem esconder o que ainda não tocou. */
@media print {
  .js .cena .a:not(.sw-ini) { opacity: 1 !important; animation: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .is-play .a { animation: none !important; }
  .js .cena .a:not(.sw-ini):not(.notif):not(.flash):not(.scan) { opacity: 1; }
}

/* -------------------------------------------------- mini-cenas (desafios) == */
.micro { display: grid; gap: var(--space-2); min-height: 96px; margin-bottom: var(--space-3); padding: var(--space-3); border-radius: var(--radius-md); background: var(--bg-subtle); align-content: center; }
.micro__linha { display: block; height: 7px; border-radius: 4px; background: var(--border-strong); opacity: .55; transform-origin: left; }
.micro__linha:nth-child(2) { width: 82%; } .micro__linha:nth-child(3) { width: 55%; }
.micro__risco { position: relative; }
.micro__risco::after { content: ""; position: absolute; left: -2%; right: -2%; top: 50%; height: 2px; background: var(--error-solid); transform-origin: left; }
.micro__bolhas { display: grid; gap: var(--space-1); }
.micro__bolhas span { display: block; width: 72%; padding: 4px var(--space-2); border-radius: var(--radius-sm); background: var(--bg-muted); font-size: 12px; line-height: 16px; color: var(--text-secondary); }
.micro__bolhas span:nth-child(even) { justify-self: end; width: 58%; }
.micro__onda { position: relative; display: grid; place-items: center; height: 72px; color: var(--error-text); }
.micro__onda::before, .micro__onda::after { content: ""; position: absolute; width: 44px; height: 44px; border: 2px solid var(--error-solid); border-radius: 50%; opacity: 0; }
.is-play .micro__onda::before { animation: onda 1.2s var(--ease-standard) 300ms 2 backwards; }
.is-play .micro__onda::after  { animation: onda 1.2s var(--ease-standard) 700ms 2 backwards; }
@keyframes onda { 0% { opacity: .7; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.7); } }

.dz-card .micro { height: 100px; padding: var(--space-2) var(--space-3); min-height: 0; margin-bottom: 0; background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.micro__abas { display: flex; flex-wrap: wrap; gap: 4px; }
.micro__abas span { padding: 2px var(--space-2); border-radius: var(--radius-xs); background: var(--bg-muted); font-size: 12px; line-height: 16px; color: var(--text-secondary); }
@media (prefers-reduced-motion: reduce) { .is-play .micro__onda::before, .is-play .micro__onda::after { animation: none; } }

/* ----------------------------------------------------- tilt (demos) == */
[data-tilt] { transform-style: preserve-3d; will-change: auto; }
[data-tilt].is-solto { transition: transform var(--duration-spring) var(--ease-spring); }
