:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2b2320;
  --muted: #7a6d64;
  --line: #eadfd2;
  --gold: #b8893b;
  --gold-dark: #8f6624;
  --stage: #1c1714;
  --radius: 14px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Cabeçalho */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 16px 10px;
}
.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: .02em;
}
.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--gold-dark);
}

/* Layout */
.layout {
  display: grid;
  gap: 16px;
  padding: 0 16px 24px;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
  }
  .stage {
    aspect-ratio: auto !important;
    height: calc(100vh - 90px);
    max-height: none !important;
    position: sticky !important;
    top: 16px;
  }
}

/* Palco da câmera */
.stage {
  position: relative;
  aspect-ratio: 3 / 4;
  max-height: 64svh;
  width: 100%;
  background: var(--stage);
  border-radius: var(--radius);
  overflow: hidden;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.stage.photo canvas { object-fit: contain; }
.stage.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  animation: flash .35s ease-out forwards;
}
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.start {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: #f6efe6;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(184,137,59,.35), transparent 60%),
    var(--stage);
}
.start h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.1;
}
.start p { margin: 0 0 6px; max-width: 34ch; color: #d9cfc4; }
.start .privacy { font-size: 12px; color: #a99d92; margin-top: 6px; }
.error {
  color: #ffd2c7 !important;
  background: rgba(160, 40, 20, .35);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #f6efe6;
  background: rgba(28, 23, 20, .55);
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 16, 14, .72);
  color: #fff;
  font-size: 13px;
  text-align: center;
}

.stage-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
}
.stage-actions[hidden] { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 16, 14, .55);
  color: #fff;
  cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }

.shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255,255,255,.35);
  cursor: pointer;
  transition: transform .1s;
}
.shutter:active { transform: scale(.92); }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: 600 15px var(--sans);
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--gold); color: #fff; }
.btn.primary:hover { background: var(--gold-dark); }
.btn.ghost { background: transparent; color: #f6efe6; border-color: rgba(246,239,230,.4); }
.btn.link { background: none; color: var(--gold-dark); padding: 0; min-height: 32px; font-weight: 500; }

/* Painel de produtos */
.panel { display: grid; gap: 14px; min-width: 0; }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #f1e9de;
  border-radius: 999px;
  padding: 4px;
}
.tabs button {
  border: 0;
  background: none;
  padding: 9px 0;
  border-radius: 999px;
  font: 500 14px var(--sans);
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(60, 40, 20, .12);
}

.products {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
}
@media (min-width: 900px) {
  .products {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    overflow: visible;
  }
}

.card {
  flex: 0 0 112px;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.card[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,137,59,.15); }
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  padding: 10px;
  background: #f7f1e8;
  border-radius: 8px;
  margin-bottom: 4px;
}
.card .name { font-size: 12.5px; font-weight: 500; line-height: 1.25; }
.card .price { font-size: 12px; color: var(--muted); }

.selected {
  display: grid;
  gap: 4px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}
.selected h3 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 600; }
.selected .price { font-size: 18px; font-weight: 600; color: var(--gold-dark); }
.selected p { margin: 2px 0 10px; color: var(--muted); font-size: 14px; }

.adjust {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}
.adjust summary { cursor: pointer; font-weight: 500; }
.adjust label {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.adjust label[hidden] { display: none; }
.adjust input[type="range"] { width: 100%; accent-color: var(--gold); }
.adjust .row { display: flex; justify-content: space-between; }
.adjust output { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.calibrate {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f7f1e8;
  font-size: 13px;
  color: var(--muted);
}
.calibrate code {
  font: 500 13px ui-monospace, Consolas, monospace;
  color: var(--ink);
  white-space: pre;
}
.calibrate .btn { justify-self: start; }
.adjust select {
  font: inherit;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

/* Modo diagnóstico (?debug) */
.debug-panel {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  max-width: calc(100% - 16px);
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .75);
  color: #9effa0;
  font: 11px/1.4 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  pointer-events: none;
}
