:root {
  --pink: #e8608f;
  --yellow: #f2c46d;
  --brown: #7a4a26;
  --ink: #4a2a12;
  --bg: #fbf3e4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse 22px 16px at 20% 25%, rgba(122, 74, 38, 0.12) 0 98%, transparent) 0 0 / 120px 110px,
    radial-gradient(ellipse 14px 18px at 70% 75%, rgba(232, 96, 143, 0.14) 0 98%, transparent) 0 0 / 90px 100px,
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; }
.screen.active { display: block; }

/* ---------- Home ---------- */
#home {
  max-width: 900px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px 40px;
}

.preview-banner {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 600;
  text-align: center;
  box-shadow: 0 4px 12px rgba(74, 42, 18, 0.2);
}
.preview-banner[hidden] { display: none; }

.hero { text-align: center; margin: 12px 0 24px; }
.hero-kicker {
  display: inline-block;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--yellow);
  font-weight: 600;
}
.hero h1 {
  font-family: 'Rye', Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.1rem, 9vw, 3.6rem);
  line-height: 1.2;
  margin: 14px 0 6px;
  color: var(--brown);
  text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(232, 96, 143, 0.45);
}
.hero-sub { margin: 0; font-size: 1.1rem; }
.hero-note { margin: 6px 0 0; font-size: 0.95rem; opacity: 0.75; }

.upload-status { margin: 0; font-size: 0.95rem; opacity: 0.85; }
.upload-status.ok { color: #9be7a5; opacity: 1; }
.upload-status.erro { color: #ffb4b4; opacity: 1; }

/* cards lado a lado: --n = quantidade de layouts (máx. 3 por linha), definido no app.js */
.grid {
  --n: 2;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  max-width: calc(var(--n) * 220px);
  margin: 0 auto;
  gap: 10px;
}

.recado {
  max-width: 560px;
  margin: 20px auto 0;
  padding: 16px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(58, 42, 74, 0.12);
}
.recado-titulo {
  display: block;
  margin-bottom: 8px;
  font-family: 'Rye', Georgia, serif;
  font-size: 1.15rem;
  color: var(--brown);
}
.recado textarea,
.recado input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e6d6bd;
  border-radius: 12px;
  background: #fffdf8;
  color: var(--ink);
  font: 400 1rem 'Fredoka', sans-serif;
}
.recado textarea { resize: none; }
.recado textarea:focus,
.recado input:focus { outline: 2px solid var(--pink); outline-offset: 1px; }
.recado-rodape {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.recado-contador { flex: none; font-size: 0.85rem; opacity: 0.6; }
.recado-dica { margin: 10px 0 0; font-size: 0.9rem; opacity: 0.75; }

.missao-chamada {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  margin: 14px auto 0;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--brown);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(74, 42, 18, 0.25);
}
.missao-chamada > span:first-child { font-size: 1.8rem; }
.missao-chamada strong { display: block; font-family: 'Rye', Georgia, serif; font-weight: 400; font-size: 1.1rem; }

@media (max-width: 480px) {
  .hero { margin: 4px 0 16px; }
  .hero h1 { margin: 8px 0 4px; }
  .card { padding: 5px 5px 8px; border-radius: 14px; }
  .card-thumb { border-radius: 10px; }
  .card-name { margin-top: 5px; font-size: 0.9rem; }
}

.card {
  appearance: none;
  border: 0;
  padding: 8px 8px 12px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(58, 42, 74, 0.12);
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: transform 0.15s;
}
.card:active { transform: scale(0.96); }
.card-thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(160deg, #b9c7d8, #e7d6c9 55%, #a8b59a);
}
.card-thumb::before {
  /* silhueta para dar ideia de onde a pessoa fica */
  content: '';
  position: absolute;
  left: 50%;
  bottom: 18%;
  width: 46%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 255, 255, 0.55) 0 22%, transparent 23%),
    radial-gradient(ellipse at 50% 110%, rgba(255, 255, 255, 0.55) 0 48%, transparent 49%);
}
.card-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.card-name {
  display: block;
  margin-top: 8px;
  font-weight: 600;
  font-size: 1.05rem;
}
.loading { grid-column: 1 / -1; text-align: center; }

/* ---------- Câmera ---------- */
.camera.active,
.result.active {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #120c18;
  color: #fff;
}

.stage {
  position: relative;
  width: min(100vw, calc((100dvh - 150px) * 3 / 4));
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #000;
  border-radius: 12px;
}
.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage video.mirror { transform: scaleX(-1); }
.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 9rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
}
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.go { animation: flash 0.4s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.cam-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: rgba(18, 12, 24, 0.85);
}
.cam-error[hidden] { display: none; }

.topbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.controls {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}

.icon-btn {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
}
.pill-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font: 600 1rem 'Fredoka', sans-serif;
  cursor: pointer;
}
.pill-btn[aria-pressed='true'] { background: var(--yellow); color: var(--ink); }

.shutter {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 6px solid #fff;
  background: var(--pink);
  cursor: pointer;
  transition: transform 0.1s;
}
.shutter:active { transform: scale(0.9); }
.shutter:disabled { opacity: 0.5; }

/* ---------- Resultado ---------- */
.result.active { gap: 18px; padding: 16px; }
.result-img {
  width: min(100%, calc((100dvh - 190px) * 3 / 4));
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn {
  display: inline-block;
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  background: #fff;
  color: var(--ink);
  font: 600 1.05rem 'Fredoka', sans-serif;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--pink); color: #fff; }
.btn[hidden] { display: none; }
.btn.small { padding: 9px 16px; font-size: 0.95rem; }
.btn.publish { background: #3f8f4f; color: #fff; }

.home-config { text-align: center; margin-top: 28px; }
.home-config .btn { box-shadow: 0 4px 14px rgba(74, 42, 18, 0.15); }

/* ---------- Configuração ---------- */
#config {
  max-width: 1000px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 60px;
}
.cfg-header h1 {
  font-family: 'Rye', Georgia, serif;
  font-weight: 400;
  color: var(--brown);
  margin: 0 0 8px;
}
.cfg-header p { margin: 0 0 14px; line-height: 1.45; }
.cfg-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.cfg-toolbar .btn:not(.primary) { box-shadow: inset 0 0 0 2px rgba(74, 42, 18, 0.25); }
.cfg-status { font-size: 0.95rem; opacity: 0.8; }

.cfg-section,
.cfg-card {
  margin-top: 20px;
  padding: 18px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(74, 42, 18, 0.1);
}
.cfg-section h2 { margin: 0 0 12px; font-size: 1.25rem; }

#config label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
  font-size: 0.95rem;
}
#config input[type='text'],
#config input[type='number'],
#config select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #e6d6bd;
  border-radius: 12px;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: #fffdf8;
}
#config input:focus,
#config select:focus { outline: 2px solid var(--pink); outline-offset: 1px; }

.cfg-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1.5fr;
  gap: 12px;
}
.cfg-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
}
.cfg-colors label { align-items: center; }
.cfg-colors input[type='color'] {
  width: 52px;
  height: 40px;
  padding: 0;
  border: 2px solid #e6d6bd;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}
.hint { margin: 10px 0 0; font-size: 0.9rem; opacity: 0.75; }
.hint code { background: #f6e7c8; padding: 1px 5px; border-radius: 6px; }

.cfg-guide-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.cfg-guide-grid > div {
  padding: 12px 16px;
  border-radius: 14px;
  background: #fbf3e4;
}
.cfg-guide h3 { margin: 0 0 6px; font-size: 1.05rem; color: var(--brown); }
.cfg-guide ul { margin: 0; padding-left: 20px; line-height: 1.5; }
.cfg-size-hint { margin: 0; }

.cfg-card {
  display: grid;
  grid-template-columns: minmax(200px, 300px) 1fr;
  gap: 20px;
  align-items: start;
}
#config label.cfg-qtd select { max-width: 260px; }
#config label.cfg-check-grande { font-size: 1.05rem; }
.cfg-preview canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.cfg-fields { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.cfg-fields h3 { margin: 0; font-size: 1.3rem; }
.cfg-texts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#config label.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: 20px; height: 20px; accent-color: var(--pink); }

.cfg-image {
  border: 2px dashed #e6d6bd;
  border-radius: 14px;
  padding: 12px 14px 14px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.cfg-image legend { padding: 0 6px; font-weight: 600; }
.cfg-img-controls,
.cfg-sticker-controls { display: flex; flex-direction: column; gap: 12px; }
.cfg-img-controls[hidden],
.cfg-sticker-controls[hidden] { display: none; }
#config label.file-btn {
  display: inline-block;
  align-self: flex-start;
  background: var(--yellow);
  font-weight: 600;
  cursor: pointer;
}
.cfg-remover { align-self: flex-start; box-shadow: inset 0 0 0 2px rgba(74, 42, 18, 0.25); }
#config input[type='range'] { width: 100%; accent-color: var(--pink); }

@media (max-width: 640px) {
  .cfg-row { grid-template-columns: 1fr 1fr; }
  .cfg-row label:first-child { grid-column: 1 / -1; }
  .cfg-card,
  .cfg-guide-grid { grid-template-columns: 1fr; }
  .cfg-preview { width: min(100%, 300px); margin: 0 auto; }
  .cfg-texts { grid-template-columns: 1fr; }
}
