/* ─── Modo Foto — interface + controle por gestos + LGPD/Instagram ───────── */

:root {
  --urban-yellow: #f2c500;
  --urban-yellow-strong: #e0b700;
  --urban-black: #050505;
  --urban-white: #ffffff;
  --urban-muted: rgba(255, 255, 255, 0.74);
  --urban-border: rgba(242, 197, 0, 0.34);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --photo-popup-bottom: max(1rem, calc(3vh + var(--safe-bottom)));
  --photo-popup-width: min(92vw, 660px);
  --instagram-duration: 10s;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--urban-black);
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--urban-white);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

#photo-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(242, 197, 0, 0.10), transparent 36%),
    var(--urban-black);
}

/* Câmera e foto capturada */
#camera-video,
#captured-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.32s ease, visibility 0.32s ease;
}

#camera-video {
  transform: scaleX(-1);
}

#captured-photo {
  transform: none;
}

#camera-video.active,
#captured-photo.active {
  opacity: 1;
  visibility: visible;
}

/* Camada escura */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.68),
      rgba(0, 0, 0, 0.16) 42%,
      rgba(0, 0, 0, 0.74)
    );
  transition: background 0.35s ease;
}

#photo-app[data-state="preview"] .overlay,
#photo-app[data-state="lgpd"] .overlay {
  background:
    linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.34),
      rgba(0, 0, 0, 0.06) 45%,
      rgba(0, 0, 0, 0.78)
    );
}

#photo-app[data-state="waiting"] .overlay,
#photo-app[data-state="done"] .overlay,
#photo-app[data-state="instagram"] .overlay,
#photo-app[data-state="error"] .overlay {
  background: rgba(0, 0, 0, 0.78);
}

/* Título fixo */
.top-label {
  position: absolute;
  top: calc(var(--safe-top) + 1rem);
  left: 50%;
  z-index: 10;
  transform: translateX(-50%);

  padding: 0.52rem 0.9rem;
  border: 1px solid rgba(242, 197, 0, 0.22);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.48);
  backdrop-filter: blur(12px);

  color: var(--urban-yellow);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

#photo-app[data-state="waiting"] #photo-title,
#photo-app[data-state="done"] #photo-title,
#photo-app[data-state="instagram"] #photo-title {
  opacity: 0;
}

/* Telas */
.screen {
  position: absolute;
  inset: 0;
  z-index: 5;

  display: flex;
  align-items: flex-end;
  justify-content: center;

  padding: 1.5rem;
  padding-bottom: var(--photo-popup-bottom);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px);

  transition:
    opacity 0.34s ease,
    transform 0.34s ease,
    visibility 0.34s ease;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.screen.active .content-card,
.screen.active .countdown-box,
.screen.active .preview-panel,
.screen.active .done-card,
.screen.active .instagram-panel {
  animation: panel-in 0.38s ease both;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }

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

/* Marca */
.brand {
  position: absolute;
  top: calc(var(--safe-top) + 1.4rem);
  left: 2rem;
  color: var(--urban-yellow);
  font-size: clamp(2.8rem, 7vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 0.8;
}

.brand span {
  display: block;
  margin-left: 0.18em;
  margin-top: 0.25rem;
  color: var(--urban-white);
  font-size: 0.28em;
  font-weight: 600;
  letter-spacing: 0.42em;
}

.done-brand {
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

/* Cards e popups */
.content-card,
.countdown-box,
.done-card,
.preview-panel,
.instagram-panel {
  position: relative;
  z-index: 8;
  width: var(--photo-popup-width);
  max-width: var(--photo-popup-width);
  margin: 0 auto;
  padding: 1.35rem 1.5rem;

  border: 1px solid rgba(242, 197, 0, 0.24);
  border-radius: 24px;
  background: rgba(5, 5, 5, 0.78);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.38);

  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  margin-bottom: 0.8rem;
  padding: 0.4rem 0.75rem;

  color: var(--urban-yellow);
  border: 1px solid var(--urban-border);
  border-radius: 999px;

  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
}

h1,
h2 {
  text-transform: uppercase;
}

h1 {
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1.02;
}

h2 {
  margin-bottom: 0.55rem;
  font-size: clamp(1.7rem, 5vw, 3.2rem);
  line-height: 1.05;
}

.description,
.content-card p,
.countdown-box p,
.done-card p,
.preview-panel p,
.instagram-panel p {
  color: var(--urban-muted);
  font-size: clamp(0.96rem, 2.2vw, 1.22rem);
  line-height: 1.38;
}

.strong-text {
  color: var(--urban-white) !important;
  font-weight: 900;
}

.hand-hint {
  margin-bottom: 0.95rem;
  font-weight: 800;
}

.auto-hint {
  margin-top: 0.85rem;
  color: rgba(255, 255, 255, 0.86) !important;
  font-size: 0.85rem !important;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Escolhas por gesto */
.gesture-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1.1rem;
}

.gesture-choice.compact {
  margin-top: 1rem;
}

.gesture-option {
  min-height: 112px;
  padding: 0.9rem 0.7rem;
  border: 1px solid rgba(242, 197, 0, 0.24);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.gesture-option strong {
  font-size: clamp(2.5rem, 7vw, 4.2rem);
  line-height: 1;
  filter: drop-shadow(0 8px 20px rgba(242, 197, 0, 0.18));
}

.gesture-option span {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
}

.gesture-option.yes {
  border-color: rgba(242, 197, 0, 0.42);
  background: rgba(242, 197, 0, 0.12);
}

.gesture-option.no {
  border-color: rgba(255, 255, 255, 0.12);
}

/* LGPD */
.lgpd-card {
  width: min(92vw, 760px);
  max-width: min(92vw, 760px);
}

.legal-text,
.legal-note {
  margin-top: 0.75rem;
  padding: 0.78rem 0.9rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.82) !important;
  font-size: clamp(0.82rem, 1.8vw, 1rem) !important;
  text-align: left;
}

.legal-note {
  border: 1px solid rgba(242, 197, 0, 0.26);
  background: rgba(242, 197, 0, 0.10);
}

/* Botões */
.btn {
  width: 100%;
  margin-top: 1rem;
  padding: 1rem 1.2rem;

  border: none;
  border-radius: 16px;

  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;

  cursor: pointer;
  user-select: none;

  transition:
    transform 0.18s ease,
    background 0.18s ease,
    color 0.18s ease,
    border 0.18s ease,
    box-shadow 0.18s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  color: #000;
  background: var(--urban-yellow);
}

.btn.primary:hover {
  background: var(--urban-yellow-strong);
}

.btn.secondary {
  color: var(--urban-white);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.09);
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* Moldura de rosto */
#face-frame {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  width: min(58vw, 420px);
  height: min(58vw, 420px);
  transform: translate(-50%, -60%);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#face-frame.active {
  opacity: 1;
  visibility: visible;
}

.corner {
  position: absolute;
  width: 52px;
  height: 52px;
  border-color: var(--urban-yellow);
}

.top-left {
  top: 0;
  left: 0;
  border-top: 4px solid;
  border-left: 4px solid;
  border-radius: 16px 0 0 0;
}

.top-right {
  top: 0;
  right: 0;
  border-top: 4px solid;
  border-right: 4px solid;
  border-radius: 0 16px 0 0;
}

.bottom-left {
  bottom: 0;
  left: 0;
  border-bottom: 4px solid;
  border-left: 4px solid;
  border-radius: 0 0 0 16px;
}

.bottom-right {
  right: 0;
  bottom: 0;
  border-right: 4px solid;
  border-bottom: 4px solid;
  border-radius: 0 0 16px 0;
}

/* Status separado do título para não cobrir “MODO FOTO INTERATIVO” */
#hand-status {
  position: absolute;
  top: calc(var(--safe-top) + 1rem);
  right: 1rem;
  z-index: 12;

  width: max-content;
  max-width: min(42vw, 430px);
  padding: 0.68rem 0.85rem;

  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(242, 197, 0, 0.22);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.62);
  backdrop-filter: blur(12px);

  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1.15;
  text-align: center;
  text-transform: uppercase;

  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

#hand-status.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#hand-status.warning {
  color: #000;
  background: rgba(242, 197, 0, 0.94);
}

#hand-status.success {
  color: #000;
  background: rgba(255, 255, 255, 0.94);
}

/* Contagem */
#countdown-number {
  --count-progress: 0%;

  position: relative;
  isolation: isolate;

  width: clamp(105px, 18vw, 155px);
  height: clamp(105px, 18vw, 155px);
  margin: 1rem auto 0;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;

  color: var(--urban-white);
  font-size: clamp(3.1rem, 8vw, 5.5rem);
  font-weight: 900;

  background:
    conic-gradient(
      var(--urban-yellow) var(--count-progress),
      rgba(242, 197, 0, 0.18) 0
    );

  box-shadow:
    0 0 0 6px rgba(242, 197, 0, 0.10),
    0 0 36px rgba(242, 197, 0, 0.18);
}

#countdown-number::before {
  content: "";
  position: absolute;
  inset: 9px;
  z-index: -1;
  border-radius: 50%;
  background: rgba(5, 5, 5, 0.88);
}

#countdown-number.tick-pop {
  animation: countdown-pop 0.28s ease both;
}

@keyframes countdown-pop {
  0% {
    transform: scale(0.88);
  }

  55% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
  }
}

/* Preview */
.preview-panel {
  width: min(92vw, 620px);
  max-width: min(92vw, 620px);
  padding: 1.2rem;
}

.preview-panel h2 {
  margin-bottom: 0.65rem;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.preview-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.preview-actions .btn {
  margin-top: 0;
}

/* Instagram / QR */
#photo-app[data-state="instagram"] .screen[data-screen="instagram"] {
  align-items: center;
  padding-bottom: 1.5rem;
}

.instagram-panel {
  width: min(94vw, 980px);
  max-width: min(94vw, 980px);
  overflow: hidden;
  padding: clamp(1.1rem, 2vw, 1.7rem);
  border-color: rgba(242, 197, 0, 0.34);
  background:
    linear-gradient(135deg, rgba(242, 197, 0, 0.14), rgba(255, 255, 255, 0.06)),
    rgba(5, 5, 5, 0.86);
}

.instagram-copy h2 {
  font-size: clamp(2rem, 5vw, 4rem);
}

.instagram-content {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.65fr);
  gap: 1rem;
  margin-top: 1.1rem;
  align-items: stretch;
}

.instagram-example,
.qr-card {
  min-height: 280px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.instagram-example {
  position: relative;
}

.instagram-example img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 280px;
  object-fit: cover;
}

.instagram-example img.is-missing {
  display: none;
}

.instagram-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  background:
    radial-gradient(circle at center, rgba(242, 197, 0, 0.24), transparent 48%),
    linear-gradient(135deg, #151515, #050505);
}

.instagram-example img.is-missing + .instagram-placeholder {
  display: flex;
}

.instagram-placeholder span {
  color: var(--urban-yellow);
  font-size: clamp(3rem, 8vw, 5.5rem);
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 0.8;
}

.instagram-placeholder strong {
  color: #fff;
  font-size: clamp(0.9rem, 2vw, 1.25rem);
  letter-spacing: 0.45em;
}

.instagram-placeholder small {
  color: rgba(255, 255, 255, 0.72);
  font-weight: 800;
  text-transform: uppercase;
}

.qr-card {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.qr-card img {
  width: min(46vw, 230px);
  height: min(46vw, 230px);
  padding: 0.5rem;
  border-radius: 18px;
  background: #fff;
  object-fit: contain;
}

.qr-card strong {
  color: var(--urban-yellow);
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 900;
}

.qr-card small {
  color: rgba(255, 255, 255, 0.72);
  font-weight: 800;
  text-transform: uppercase;
}

.return-progress {
  width: 100%;
  height: 7px;
  margin-top: 1rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.return-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--urban-yellow);
}

#photo-app[data-state="instagram"] .return-progress span {
  animation: return-fill var(--instagram-duration) linear forwards;
}

@keyframes return-fill {
  to {
    width: 100%;
  }
}

/* Final */
.done-card {
  margin-bottom: 0.5rem;
}

.loader {
  width: 74px;
  height: 74px;
  margin: 1.5rem auto 0;
  border: 8px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--urban-yellow);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#capture-canvas {
  display: none;
}

/* Responsivo */
@media (max-width: 880px) {
  #hand-status {
    top: calc(var(--safe-top) + 3.45rem);
    left: 50%;
    right: auto;
    max-width: min(92vw, 520px);
    transform: translate(-50%, -4px);
    font-size: 0.68rem;
  }

  #hand-status.active {
    transform: translate(-50%, 0);
  }

  .instagram-content {
    grid-template-columns: 1fr;
  }

  .instagram-example,
  .qr-card {
    min-height: 220px;
  }

  .instagram-example img {
    min-height: 220px;
  }
}

@media (orientation: portrait) {
  :root {
    --photo-popup-bottom: max(0.9rem, calc(2vh + var(--safe-bottom)));
    --photo-popup-width: min(94vw, 560px);
  }

  .screen {
    padding: 1rem;
    padding-bottom: var(--photo-popup-bottom);
  }

  .top-label {
    top: calc(var(--safe-top) + 0.75rem);
    font-size: 0.68rem;
  }

  #hand-status {
    top: calc(var(--safe-top) + 3.05rem);
    left: 50%;
    right: auto;
    width: max-content;
    max-width: 92vw;
    padding: 0.58rem 0.72rem;
    font-size: 0.62rem;
  }

  .content-card,
  .countdown-box,
  .done-card,
  .preview-panel,
  .instagram-panel {
    padding: 1.05rem 1rem;
    border-radius: 22px;
  }

  h1 {
    font-size: clamp(1.85rem, 7vw, 2.6rem);
  }

  h2 {
    font-size: clamp(1.55rem, 6vw, 2.2rem);
  }

  .gesture-choice,
  .preview-actions {
    grid-template-columns: 1fr;
  }

  .gesture-option {
    min-height: 78px;
    flex-direction: row;
    justify-content: flex-start;
    padding: 0.72rem 0.9rem;
    text-align: left;
  }

  .gesture-option strong {
    min-width: 58px;
    font-size: 2.8rem;
  }

  #face-frame {
    width: min(72vw, 390px);
    height: min(72vw, 390px);
    transform: translate(-50%, -66%);
  }

  #countdown-number {
    width: clamp(92px, 25vw, 125px);
    height: clamp(92px, 25vw, 125px);
    font-size: clamp(2.8rem, 10vw, 4.5rem);
  }

  .done-brand {
    top: calc(var(--safe-top) + 1rem);
  }

  .legal-text,
  .legal-note {
    font-size: 0.78rem !important;
  }

  #photo-app[data-state="instagram"] .screen[data-screen="instagram"] {
    align-items: flex-end;
  }

  .instagram-content {
    gap: 0.75rem;
    margin-top: 0.85rem;
  }

  .instagram-example {
    min-height: 185px;
  }

  .instagram-example img {
    min-height: 185px;
  }

  .qr-card {
    min-height: auto;
  }

  .qr-card img {
    width: min(48vw, 190px);
    height: min(48vw, 190px);
  }
}

@media (max-height: 620px) {
  .content-card,
  .countdown-box,
  .done-card,
  .preview-panel,
  .instagram-panel {
    padding: 0.9rem 1rem;
  }

  .description,
  .content-card p,
  .countdown-box p,
  .done-card p,
  .preview-panel p,
  .instagram-panel p {
    font-size: 0.9rem;
  }

  .gesture-option {
    min-height: 70px;
  }

  .gesture-option strong {
    font-size: 2.5rem;
  }

  #countdown-number {
    width: 88px;
    height: 88px;
    font-size: 3rem;
  }

  .legal-text,
  .legal-note {
    display: none;
  }

  .instagram-example {
    display: none;
  }

  .instagram-content {
    grid-template-columns: 1fr;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.photo-card .preview {
  aspect-ratio: 4 / 3;
}

.photo-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.download-link {
  display: block;
  text-align: center;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  text-decoration: none;
}

@media (max-width: 680px) {
  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .count,
  .header-actions button {
    width: 100%;
    text-align: center;
  }
}