/* ─────────────────────────────────────────────────────────────
   Arquivo — mobile-first
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #151311;
  --bg-2: #1d1a17;
  --ink: #ece6da;
  --ink-dim: #a39b8e;
  --accent: #d9c7a2;
  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --gutter: 20px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% 0%, #24201c 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* grão de papel muito subtil */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }

/* ── Cabeçalho ─────────────────────────────────────────────── */
.masthead {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: calc(56px + env(safe-area-inset-top)) var(--gutter) 40px;
}
.masthead__kicker,
.masthead__sub {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.masthead__title {
  margin: 14px 0 12px;
  font-weight: 300;
  font-size: clamp(44px, 13vw, 96px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variation-settings: 'opsz' 144;
}

/* ── Wall ──────────────────────────────────────────────────── */
.wall {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 56px var(--gutter);
  align-items: start;
  padding: 8px max(var(--gutter), env(safe-area-inset-left)) 140px;
  max-width: 1240px;
  margin: 0 auto;
}
@media (min-width: 640px) {
  .wall { grid-template-columns: repeat(2, 1fr); gap: 64px 40px; padding-inline: 40px; }
}
@media (min-width: 1040px) {
  .wall { grid-template-columns: repeat(3, 1fr); gap: 72px 56px; }
}

.wall__item {
  container-type: inline-size;
  cursor: zoom-in;
  outline: none;
  border-radius: 2px;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.4s var(--ease-out);
  max-width: 440px;
  width: 100%;
  justify-self: center;
}
.wall__item:focus-visible { outline: 1px solid var(--accent); outline-offset: 10px; }
@media (hover: hover) {
  .wall__item:hover { transform: translateY(-3px); }
}
/* desfasamento editorial ligeiro nas curadas em ecrãs largos */
@media (min-width: 640px) {
  .wall__item--curated:nth-child(odd) { margin-top: 28px; }
}

.wall__item.is-landing { visibility: hidden; }
.wall__item.just-landed .frame { animation: landed-glow 1.6s var(--ease-out); }
@keyframes landed-glow {
  0% { box-shadow: var(--frame-shadow), 0 0 0 0 rgba(217, 199, 162, 0.55); }
  100% { box-shadow: var(--frame-shadow), 0 0 0 26px rgba(217, 199, 162, 0); }
}

.wall__empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-dim);
  font-style: italic;
  padding: 80px 0;
}
.wall__skeleton {
  aspect-ratio: 4 / 5.6;
  max-width: 440px;
  width: 100%;
  justify-self: center;
  background: linear-gradient(100deg, #1e1b18 30%, #26221e 50%, #1e1b18 70%) 0 0 / 300% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -150% 0; } }

/* ── Moldura ───────────────────────────────────────────────── */
/* Os valores vêm de js/frames.js via custom properties. O elemento pai tem
   container-type: inline-size, por isso cqi = % da largura da moldura. */
.frame {
  --frame-shadow:
    0 1px 0 0 rgba(255, 255, 255, 0.06),
    0 30px 50px -28px rgba(0, 0, 0, 0.85),
    0 6px 14px -6px rgba(0, 0, 0, 0.55);
  position: relative;
  margin: 0;
  width: 100%;
  padding: var(--f-border, 14px);
  background:
    linear-gradient(135deg, var(--f-frame-hi) 0%, transparent 38%, transparent 62%, rgba(0, 0, 0, 0.25) 100%),
    var(--f-frame);
  border-radius: 1.5px;
  box-shadow: var(--frame-shadow);
  transition: background-color 0.12s linear;
  isolation: isolate;
}
/* chanfro interior entre moldura e passe-partout */
.frame::before {
  content: '';
  position: absolute;
  inset: calc(var(--f-border, 14px) - 2px);
  border: 2px solid rgba(0, 0, 0, 0.22);
  border-top-color: rgba(0, 0, 0, 0.38);
  border-left-color: rgba(0, 0, 0, 0.32);
  pointer-events: none;
  z-index: 2;
}
/* camada de flash para a selagem */
.frame::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, #fffaf0 0%, rgba(255, 250, 240, 0.6) 40%, transparent 75%);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  mix-blend-mode: screen;
}

.frame__mat {
  background: var(--f-mat);
  padding: var(--f-matpad, 24px);
  padding-bottom: calc(var(--f-matpad, 24px) * 0.7);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.16), inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  transition: background-color 0.12s linear;
}

.frame__window {
  position: relative;
  aspect-ratio: var(--ar, 0.8);
  overflow: hidden;
  background: color-mix(in srgb, var(--f-mat) 82%, #000);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
/* corte em bisel do passe-partout por cima da foto */
.frame__window::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.25), inset -1px -1px 0 rgba(255, 255, 255, 0.35);
  pointer-events: none;
}
.frame__photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 0.6s var(--ease-out), transform 0.9s var(--ease-out);
}
.frame.is-loaded .frame__photo { opacity: 1; transform: none; }
.frame:not(.is-filled) .frame__photo { display: none; }

/* Cartão tipográfico — desliza para dentro quando há texto */
.frame__card {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  margin-top: 0;
  transform: translateY(-6px);
  transition:
    grid-template-rows 0.42s var(--ease-out),
    margin-top 0.42s var(--ease-out),
    opacity 0.32s ease,
    transform 0.42s var(--ease-out);
}
.frame.has-card .frame__card {
  grid-template-rows: 1fr;
  opacity: 1;
  margin-top: 4.5cqi;
  transform: none;
}
.frame__card-text {
  min-height: 0;
  overflow: hidden;
  margin: 0;
  background: var(--f-card);
  color: var(--f-ink);
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(14px, 6cqi, 26px);
  line-height: 1.2;
  text-align: center;
  padding: 0 4cqi;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  overflow-wrap: anywhere;
}
.frame.has-card .frame__card-text { padding-block: 3.2cqi 3.4cqi; }

.frame__meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3.4cqi;
  font-family: var(--mono);
  font-size: clamp(8.5px, 2.6cqi, 12px);
  letter-spacing: 0.08em;
  color: var(--f-ink);
  opacity: 0.66;
  white-space: nowrap;
}
.frame__meta span:last-child { overflow: hidden; text-overflow: ellipsis; text-align: right; }
.frame__meta span:empty { display: none; }

/* ── Botão de upload (só existe no DOM em modo VIP) ─────────── */
.fab {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 15px 24px 15px 18px;
  border: 1px solid rgba(236, 230, 218, 0.18);
  border-radius: 999px;
  background: rgba(28, 25, 22, 0.78);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 14px 30px -12px rgba(0, 0, 0, 0.8);
  cursor: pointer;
  animation: fab-in 0.6s var(--ease-spring) both 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: translateX(-50%) scale(0.97); }
.fab:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }
.fab__icon {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1612;
  font-size: 18px; line-height: 1;
}
@keyframes fab-in { from { opacity: 0; transform: translate(-50%, 30px); } }

/* ── Diálogos (upload + lightbox) ──────────────────────────── */
dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  max-width: 100vw;
  max-height: 100dvh;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}
dialog::backdrop {
  background: rgba(10, 9, 8, 0.86);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
dialog[open] { animation: dlg-in 0.35s var(--ease-out); }
dialog[open]::backdrop { animation: fade-in 0.35s ease; }
dialog.is-leaving::backdrop { opacity: 0; transition: opacity 0.5s ease; }
@keyframes dlg-in { from { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.stage {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: calc(24px + env(safe-area-inset-top)) var(--gutter) calc(24px + env(safe-area-inset-bottom));
}
.stage__frame {
  container-type: inline-size;
  /* largura limitada também pela altura disponível, para fotos verticais caberem */
  width: min(80vw, 380px, calc((100dvh - var(--stage-reserve, 300px)) * var(--ar, 0.8) * 0.82));
  min-width: 200px;
  flex-shrink: 0;
}

/* Loader shuffle: micro-salto a cada troca */
.stage__frame.is-shuffling .frame { animation: none; }
.frame.tick { animation: tick 0.14s steps(2, end); }
@keyframes tick {
  0% { transform: translateY(5px) scale(0.985); filter: brightness(1.25); }
  100% { transform: none; filter: none; }
}
.frame.locked { animation: lock 0.55s var(--ease-spring); }
@keyframes lock {
  0% { transform: scale(0.96); }
  60% { transform: scale(1.015); }
  100% { transform: none; }
}

.stage__status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
  min-height: 1em;
  margin: 0;
  max-width: 340px;
  text-align: center;
  line-height: 1.6;
}
.stage__status .dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* Formulário de personalização */
.personalize {
  width: min(86vw, 380px);
  display: grid;
  gap: 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.45s var(--ease-out), transform 0.45s var(--ease-out);
}
.personalize.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.personalize.is-hidden { opacity: 0; transform: translateY(6px); pointer-events: none; }
.personalize__label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-dim);
  text-align: center;
}
.personalize__field { position: relative; }
.personalize__input {
  width: 100%;
  padding: 12px 44px 12px 4px;
  border: 0;
  border-bottom: 1px solid rgba(236, 230, 218, 0.28);
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px; /* ≥16px evita zoom automático no iOS */
  text-align: center;
  border-radius: 0;
  outline: none;
  transition: border-color 0.2s;
}
.personalize__input:focus { border-bottom-color: var(--accent); }
.personalize__input::placeholder { color: rgba(236, 230, 218, 0.28); }
.personalize__count {
  position: absolute;
  right: 0;
  bottom: 14px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-dim);
  opacity: 0.7;
}
.personalize__actions { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }

.btn {
  appearance: none;
  border: 1px solid rgba(236, 230, 218, 0.22);
  background: transparent;
  color: var(--ink);
  padding: 13px 22px;
  min-width: 120px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
.btn--primary { background: var(--ink); color: #171411; border-color: var(--ink); }
.btn--ghost { border-color: transparent; color: var(--ink-dim); }
.btn[disabled], .btn[aria-busy='true'] { opacity: 0.55; pointer-events: none; }

/* Selagem: flash suave + relevo */
.frame.is-sealing { animation: seal 0.75s var(--ease-out); }
.frame.is-sealing::after { animation: flash 0.75s ease-out; }
@keyframes seal {
  0% { transform: none; }
  35% { transform: scale(1.035); box-shadow: var(--frame-shadow), 0 0 0 1px rgba(255, 255, 255, 0.25), 0 40px 80px -30px rgba(0, 0, 0, 0.9); }
  100% { transform: none; }
}
@keyframes flash {
  0% { opacity: 0; }
  22% { opacity: 0.85; }
  100% { opacity: 0; }
}

/* Lightbox */
.lightbox .stage__frame { --stage-reserve: 200px; width: min(88vw, 520px, calc((100dvh - var(--stage-reserve)) * var(--ar, 0.8) * 0.82)); }
.lightbox__close {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(236, 230, 218, 0.18);
  background: rgba(20, 18, 16, 0.6);
  font-size: 20px;
  cursor: pointer;
  z-index: 2;
}
.lightbox__actions { display: flex; gap: 10px; min-height: 46px; }

/* Toast */
.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  opacity: 0;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: #ece6da;
  color: #1a1612;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s var(--ease-out);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Rodapé */
.colophon {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 0 var(--gutter) calc(48px + env(safe-area-inset-bottom));
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
html[data-mode='vip'] .colophon { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }

/* Movimento reduzido */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Painel de debug (só localhost ou VIP + ?debug=1) ─────────── */
.dbg-toggle {
  position: fixed;
  z-index: 30;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  padding: 7px 10px;
  border: 1px dashed #e0b54a;
  border-radius: 6px;
  background: rgba(30, 24, 10, 0.85);
  color: #e0b54a;
  font: 600 10px/1 var(--mono);
  letter-spacing: 0.14em;
  cursor: pointer;
}
.dbg {
  width: min(560px, 100vw);
  height: auto;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: #1b1916;
  border: 1px solid #3a352e;
  border-radius: 14px 14px 0 0;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
}
@media (min-width: 640px) { .dbg { margin: auto; border-radius: 14px; } }
.dbg__head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.dbg__head strong { color: #e0b54a; letter-spacing: 0.14em; text-transform: uppercase; }
.dbg__meta { color: var(--ink-dim); flex: 1; }
.dbg__close { width: 34px; height: 34px; border-radius: 50%; border: 1px solid #3a352e; background: none; cursor: pointer; font-size: 18px; }
.dbg__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.dbg__btn {
  padding: 12px 10px;
  border: 1px solid #3a352e;
  border-radius: 8px;
  background: #24211d;
  font: 500 12px/1.2 var(--mono);
  text-align: left;
  cursor: pointer;
}
.dbg__btn:hover { border-color: #e0b54a; }
.dbg__btn[aria-busy='true'] { opacity: 0.5; pointer-events: none; }
.dbg__out {
  margin: 12px 0 0;
  padding: 10px;
  min-height: 60px;
  max-height: 34dvh;
  overflow: auto;
  background: #0f0e0c;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cfe8c4;
}
.dbg__h { margin: 14px 0 6px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.dbg__log { list-style: none; margin: 0; padding: 0; max-height: 26dvh; overflow: auto; }
.dbg__l { padding: 4px 0; border-bottom: 1px solid #26231f; word-break: break-word; }
.dbg__l time { color: var(--ink-dim); }
.dbg__l--warn { color: #e8c46a; }
.dbg__l--error { color: #ff8a7a; }
.dbg-preview { background: #000; }
.dbg-preview__img { width: 100%; height: calc(100% - 64px); object-fit: contain; }
.dbg-preview__bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; font-family: var(--mono); font-size: 12px; }
