/* =========================================================
   Foto Fantasma — mobile-first, dark camera UI
   ========================================================= */

:root {
  --bg: #0d0f14;
  --panel: #161a22;
  --panel-2: #212734;
  --text: #f2f4f8;
  --muted: #9aa3b5;
  --accent: #8fd3ff;
  --accent-ink: #062033;
  --danger: #ff8a80;
  --radius: 14px;
  /* Approximate height of the control panel; used to size the stage */
  --controls-h: 250px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Stage (video + ghost) ---------- */

.viewer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

/* The stage is always 3:4 (portrait), the Pixel's default photo ratio.
   Its width is limited so it never pushes the controls off screen. */
.stage {
  position: relative;
  width: min(100vw, calc((100dvh - var(--controls-h) - env(safe-area-inset-top)) * 0.75));
  aspect-ratio: 3 / 4;
  background: #000;
  overflow: hidden;
}

/* Video and ghost use the same "cover" crop, so they line up exactly */
.stage video,
.stage #ghost {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Front camera preview is mirrored (like a mirror), as phones usually do */
.stage video.mirror { transform: scaleX(-1); }

.stage #ghost {
  opacity: 0.5;
  pointer-events: none;
}
.stage #ghost.mirror { transform: scaleX(-1); }

/* Rule-of-thirds grid */
.grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.35) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.35) 1px, transparent 1px);
  background-size: calc(100% / 3) calc(100% / 3);
  background-position: -1px -1px;
}

/* White flash when taking a photo */
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease-out;
}
.flash.on { opacity: .8; transition: none; }

.status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(0,0,0,.65);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
}
.status[hidden] { display: none; }
.status p { margin: 0; max-width: 32ch; }

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
.badge:empty { display: none; }

/* ---------- Controls ---------- */

.controls {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #ffffff12;
}

.slider-row {
  display: grid;
  grid-template-columns: 64px 1fr 48px;
  align-items: center;
  gap: 10px;
  font-size: .9rem;
}
.slider-row[hidden] { display: none; }
.slider-row label { color: var(--muted); }
.slider-row output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.slider-row.compact { grid-template-columns: 80px 1fr; }

input[type="range"] {
  width: 100%;
  height: 32px;
  accent-color: var(--accent);
}
input[type="range"]:disabled { opacity: .35; }

.small-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid #ffffff22;
  background: var(--panel-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: .82rem;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.chip:disabled { opacity: .35; cursor: default; }

.main-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 2px 0;
}

.round-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.5rem;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.round-btn:active { transform: scale(.94); }

.shutter {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 5px solid #fff;
  background: #fff;
  box-shadow: inset 0 0 0 4px var(--panel);
  cursor: pointer;
  transition: transform .1s;
}
.shutter:active { transform: scale(.92); }
.shutter:disabled { opacity: .35; cursor: default; }
.shutter.busy { background: var(--muted); }

.mode-row {
  display: flex;
  justify-content: center;
  font-size: .78rem;
  color: var(--muted);
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Buttons ---------- */

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: .95rem;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost-btn { background: transparent; border: 1px solid #ffffff33; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }

/* ---------- Review dialog ---------- */

.review {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--bg);
  color: var(--text);
}
.review::backdrop { background: #000; }

.review-body {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.review-img-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.review-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
/* Ghost on top of the result, for the "Comparar" slider */
#reviewGhost {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: .85rem;
}
.info dt { color: var(--muted); }
.info dd { margin: 0; font-variant-numeric: tabular-nums; }

.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--controls-h) + 12px);
  transform: translateX(-50%) translateY(10px);
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: #000d;
  color: #fff;
  font-size: .88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Landscape on a phone: keep it usable, stage on the left, controls on the right */
@media (orientation: landscape) and (max-height: 600px) {
  body { flex-direction: row; }
  .stage {
    width: auto;
    height: calc(100dvh - env(safe-area-inset-top));
  }
  .controls {
    width: 320px;
    justify-content: center;
    border-top: none;
    border-left: 1px solid #ffffff12;
    overflow-y: auto;
  }
}
