/* Halloween Tech Cam — tema dark neon */
:root {
  --bg: #0a0610;
  --bg-2: #130a1e;
  --panel: rgba(18, 10, 30, 0.78);
  --line: rgba(157, 78, 221, 0.35);
  --orange: #ff7a00;
  --purple: #9d4edd;
  --acid: #39ff14;
  --rec: #ff2a3d;
  --text: #f4ecff;
  --muted: #a99bc4;
  --accent: var(--orange);
  --dock-w: 0px;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation; overscroll-behavior: none; -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- Botões ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  min-height: 48px; padding: 0 26px; border-radius: 999px; font-weight: 700; letter-spacing: .02em;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn-primary {
  color: #1a0b00; background: linear-gradient(135deg, #ffb347, var(--orange) 55%, #ff4d00);
  box-shadow: 0 0 0 1px rgba(255,255,255,.2) inset, 0 8px 30px rgba(255,122,0,.45);
}
.btn-primary:active { transform: scale(.96); }
.btn-secondary { background: rgba(157,78,221,.25); border: 1px solid var(--purple); color: #e9d5ff; }
.btn-ghost { color: var(--muted); border: 1px solid var(--line); }

/* ---------- Tela inicial ---------- */
.start { display: grid; place-items: center; padding: calc(var(--sat) + 20px) 20px calc(var(--sab) + 20px); overflow-y: auto; }
.start__bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(60% 45% at 50% 0%, rgba(157,78,221,.45), transparent 70%),
    radial-gradient(50% 40% at 85% 100%, rgba(255,122,0,.28), transparent 70%),
    radial-gradient(40% 30% at 10% 80%, rgba(57,255,20,.12), transparent 70%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 4px),
    var(--bg);
}
.start__card {
  position: relative; width: min(420px, 100%); text-align: center; padding: 34px 26px 26px;
  border-radius: 28px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 0 60px rgba(157,78,221,.25), 0 0 0 1px rgba(255,122,0,.08) inset;
}
.start__logo { font-size: 64px; line-height: 1; filter: drop-shadow(0 0 18px var(--orange)); animation: float 3.2s ease-in-out infinite; }
.start__title { margin: 14px 0 6px; font-size: 34px; line-height: 1.05; font-weight: 900; letter-spacing: -.01em; }
.start__title span {
  display: block; font-size: 22px; letter-spacing: .32em; text-transform: uppercase; margin-top: 8px;
  background: linear-gradient(90deg, var(--acid), var(--purple) 60%, var(--orange));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.start__tag { color: var(--muted); margin: 14px 0 24px; line-height: 1.45; }
.start__error { margin: 16px 0 0; padding: 12px 14px; border-radius: 14px; color: #ffd0d6; background: rgba(255,42,61,.14); border: 1px solid rgba(255,42,61,.45); font-size: 14px; line-height: 1.4; }
.start__help { text-align: left; margin: 12px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.start__privacy { margin: 22px 0 0; font-size: 12px; color: var(--muted); }
@keyframes float { 50% { transform: translateY(-8px) rotate(-4deg); } }

/* ---------- Tela principal ---------- */
.main { background: #000; }
.stage { position: absolute; inset: 0 var(--dock-w) 0 0; overflow: hidden; background: #000; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.stage video { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.is-on { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

.topbar {
  position: absolute; top: 0; left: 0; right: var(--dock-w); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--sat) + 10px) calc(var(--sar) + 12px) 24px calc(var(--sal) + 14px);
  background: linear-gradient(180deg, rgba(0,0,0,.6), transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar__brand { font-weight: 900; letter-spacing: .06em; text-shadow: 0 0 12px var(--orange); }
.topbar__actions { display: flex; gap: 10px; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; font-size: 20px; display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform .15s, border-color .2s, box-shadow .2s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn[aria-pressed="true"] { border-color: var(--acid); box-shadow: 0 0 14px rgba(57,255,20,.45); }

.rec {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 16px);
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: rgba(0,0,0,.6); border: 1px solid var(--rec); font-weight: 800; font-size: 13px;
  font-variant-numeric: tabular-nums; letter-spacing: .08em;
}
.rec i { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .15; } }

.hint {
  position: absolute; z-index: 4; left: 50%; transform: translateX(-50%);
  top: calc(var(--sat) + 76px); padding: 7px 14px; border-radius: 999px; font-size: 13px;
  background: rgba(0,0,0,.55); border: 1px dashed var(--purple); color: #e9d5ff;
  margin-right: calc(var(--dock-w) / 2); pointer-events: none;
}

.loading {
  position: absolute; z-index: 8; left: 0; right: var(--dock-w); top: 0; bottom: 0;
  display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center;
  background: rgba(10,6,16,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); padding: 20px;
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(157,78,221,.25); border-top-color: var(--orange); border-right-color: var(--acid);
  animation: spin .9s linear infinite; box-shadow: 0 0 22px rgba(255,122,0,.35);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dock (personagens + captura) ---------- */
.dock {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: 0;
  padding: 30px 0 calc(var(--sab) + 10px);
  background: linear-gradient(0deg, rgba(10,6,16,.96) 52%, rgba(10,6,16,.7) 80%, transparent);
}
.dock__strip { display: flex; align-items: flex-start; }
.carousel {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: flex-start; gap: 10px;
  overflow-x: auto; overflow-y: hidden; padding: 12px 8px 8px calc(var(--sal) + 16px); margin-top: -6px;
  scroll-snap-type: x proximity; scroll-padding: 0 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.carousel::-webkit-scrollbar { display: none; }

.tile {
  --c: var(--orange);
  flex: 0 0 auto; width: 70px; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted);
}
.tile__icon, .card__icon {
  position: relative; display: grid; place-items: center; border-radius: 50%; color: var(--c);
  background: radial-gradient(circle at 30% 22%, color-mix(in srgb, var(--c) 24%, #1c1233), #120a1e 72%);
  border: 2px solid color-mix(in srgb, var(--c) 32%, transparent);
  transition: transform .18s, border-color .2s, box-shadow .2s;
}
.tile__icon { width: 58px; height: 58px; }
.tile__icon svg, .card__icon svg { width: 66%; height: 66%; filter: drop-shadow(0 0 5px color-mix(in srgb, var(--c) 75%, transparent)); }
.tile__text { display: block; }
.tile__label {
  display: block; width: 70px; min-height: 2.3em; font-size: 11px; font-weight: 700; line-height: 1.15; text-align: center;
  overflow-wrap: anywhere; transition: color .2s;
}
.tile:active .tile__icon { transform: scale(.92); }
.tile.is-active .tile__icon {
  border-color: var(--c); transform: scale(1.07);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent), 0 0 22px color-mix(in srgb, var(--c) 65%, transparent);
}
.tile.is-active .tile__label { color: #fff; }
.tile--random .tile__icon, .card--random .card__icon {
  background: conic-gradient(from 210deg, rgba(255,122,0,.4), rgba(157,78,221,.4), rgba(57,255,20,.3), rgba(255,122,0,.4)), #120a1e;
}
.tile-sep { flex: 0 0 1px; align-self: stretch; margin: 8px 0 22px; background: var(--line); }

.all-btn {
  flex: 0 0 auto; width: 62px; margin: 6px calc(var(--sar) + 12px) 0 4px; padding: 0; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-size: 11px; font-weight: 700; color: var(--muted);
}
.all-btn svg {
  width: 58px; height: 58px; padding: 16px; border-radius: 18px; color: #e9d5ff;
  background: rgba(157,78,221,.18); border: 1.5px solid var(--purple); transition: transform .15s;
}
.all-btn:active svg { transform: scale(.92); }

/* Modo foto / vídeo */
.modes {
  display: flex; width: max-content; margin: 2px auto 10px; padding: 4px; border-radius: 999px;
  background: rgba(30,18,48,.9); border: 1px solid var(--line);
}
.mode {
  display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 20px; border-radius: 999px;
  font-size: 14px; font-weight: 800; letter-spacing: .02em; color: var(--muted); transition: background .2s, color .2s;
}
.mode svg { width: 19px; height: 19px; }
.mode.is-active { color: #fff; background: linear-gradient(135deg, #ff9a2e, #ff5a00); box-shadow: 0 4px 16px rgba(255,122,0,.4); }
#mode-video.is-active { background: linear-gradient(135deg, #ff4d5e, #d9142b); box-shadow: 0 4px 16px rgba(255,42,61,.45); }

/* Ações */
.actions {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 calc(var(--sar) + 26px) 0 calc(var(--sal) + 26px);
}
.side { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 60px; }
.side--left { justify-self: start; }
.side--right { justify-self: end; }
.side__label { font-size: 11px; font-weight: 700; color: var(--muted); }
.thumb {
  width: 56px; height: 56px; border-radius: 16px; overflow: hidden; padding: 0;
  border: 2px solid var(--purple); box-shadow: 0 0 14px rgba(157,78,221,.5); background: #1a0f2b;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb--empty { border: 2px dashed rgba(157,78,221,.35); box-shadow: none; background: transparent; display: block; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; color: #e9d5ff;
  background: var(--panel); border: 1.5px solid var(--line); transition: transform .15s;
}
.round-btn svg { width: 28px; height: 28px; }
.round-btn:active { transform: scale(.9) rotate(-20deg); }

.capture {
  width: 84px; height: 84px; border-radius: 50%; padding: 6px; transition: transform .12s, box-shadow .2s;
}
.capture i { display: block; width: 100%; height: 100%; border-radius: 50%; transition: border-radius .2s, transform .2s, background .2s; }
.capture:active { transform: scale(.92); }
.capture--photo {
  background: conic-gradient(from 200deg, var(--orange), var(--purple), var(--acid), var(--orange));
  box-shadow: 0 0 28px rgba(255,122,0,.5);
}
.capture--photo i { background: #fff; border: 3px solid #120a1e; }
.capture--video { background: #fff; box-shadow: 0 0 28px rgba(255,42,61,.45); }
.capture--video i { background: var(--rec); border: 3px solid #fff; }
.capture.is-recording { animation: pulse 1.3s ease-out infinite; }
.capture.is-recording i { border-radius: 14px; transform: scale(.52); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,42,61,.7); }
  100% { box-shadow: 0 0 0 24px rgba(255,42,61,0); }
}

/* ---------- Gaveta de personagens ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 18; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5,2,10,.7); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .2s ease-out;
}
.sheet__panel {
  width: min(560px, 100%); max-height: 86dvh; display: flex; flex-direction: column;
  padding: 8px calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  border-radius: 26px 26px 0 0; background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0;
  box-shadow: 0 -10px 50px rgba(157,78,221,.28); animation: rise .25s ease-out;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
.sheet__grab { width: 44px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.2); margin: 4px auto 6px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 10px; }
.sheet__head h2 { margin: 0; font-size: 18px; font-weight: 900; }
.sheet__head .icon-btn { width: 40px; height: 40px; font-size: 16px; }
.sheet__body { overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 18px; padding-bottom: 4px; }
.sheet__section h3 { margin: 0 0 10px; font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.sheet__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card {
  --c: var(--orange); min-height: 64px; padding: 8px 12px 8px 8px; display: flex; align-items: center; gap: 10px; text-align: left;
  border-radius: 18px; background: rgba(30,18,48,.8); border: 1.5px solid rgba(255,255,255,.08); color: var(--muted);
  transition: transform .15s, border-color .2s, box-shadow .2s;
}
.card:active { transform: scale(.97); }
.card__icon { flex: 0 0 auto; width: 48px; height: 48px; }
.card__label { font-size: 13px; font-weight: 800; line-height: 1.15; color: #fff; overflow-wrap: anywhere; }
.card__text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card__desc { font-size: 12px; line-height: 1.3; color: var(--muted); font-weight: 500; }
.card.is-active {
  border-color: var(--c); background: linear-gradient(135deg, color-mix(in srgb, var(--c) 22%, #120a1e), rgba(30,18,48,.9));
  box-shadow: 0 0 18px color-mix(in srgb, var(--c) 45%, transparent);
}
.sheet__section--hero .sheet__grid { grid-template-columns: 1fr; }
.sheet__section--hero .card { min-height: 76px; }
.sheet__section--hero .card__icon { width: 56px; height: 56px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  background: rgba(5,2,10,.86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: fade .2s ease-out;
}
.modal__box {
  width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 14px; padding: 14px;
  border-radius: 24px; background: var(--bg-2); border: 1px solid var(--line); box-shadow: 0 0 50px rgba(157,78,221,.3);
}
.modal__media { min-height: 0; flex: 1 1 auto; display: grid; place-items: center; overflow: hidden; border-radius: 16px; background: #000; }
.modal__media img, .modal__media video { max-width: 100%; max-height: calc(100dvh - 220px); display: block; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
.modal__hint { margin: 0; font-size: 13px; color: var(--acid); text-align: center; line-height: 1.4; }
.modal__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.modal__actions button { flex: 1 1 auto; }
@keyframes fade { from { opacity: 0; } }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 30; left: 0; right: 0; top: calc(var(--sat) + 70px);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px;
}
.toast {
  max-width: min(440px, 100%); padding: 11px 16px; border-radius: 14px; font-size: 14px; line-height: 1.35; text-align: center;
  background: rgba(18,10,30,.94); border: 1px solid var(--purple); box-shadow: 0 6px 24px rgba(0,0,0,.5);
  animation: toast-in .25s ease-out;
}
.toast--error { border-color: var(--rec); color: #ffd0d6; }
.toast--success { border-color: var(--acid); }
.toast.is-leaving { opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

/* ---------- Paisagem / desktop largo: dock lateral ---------- */
@media (orientation: landscape) and (min-width: 640px) {
  :root { --dock-w: calc(320px + var(--sar)); }
  .dock {
    left: auto; top: 0; width: var(--dock-w); display: flex; flex-direction: column; justify-content: space-between;
    padding: calc(var(--sat) + 10px) 0 calc(var(--sab) + 12px);
    background: linear-gradient(270deg, #0a0610 60%, #100820); border-left: 1px solid var(--line);
  }
  .dock__strip { flex: 1 1 auto; min-height: 0; }
  .all-btn { display: none; }
  .carousel {
    flex-wrap: wrap; align-content: flex-start; gap: 8px 6px; overflow-x: hidden; overflow-y: auto; height: 100%;
    padding: 8px calc(var(--sar) + 14px) 8px 14px; scroll-snap-type: none;
  }
  .tile { width: 68px; }
  .tile__icon { width: 52px; height: 52px; }
  .tile__label { width: 68px; font-size: 10px; letter-spacing: -.01em; }
  .tile-sep { flex-basis: 100%; height: 1px; margin: 2px 0; width: auto; align-self: auto; }
  .modes { margin-top: 8px; }
  .actions { padding: 0 calc(var(--sar) + 22px) 0 22px; }
  .topbar { right: var(--dock-w); }
  .sheet { align-items: center; }
  .sheet__panel { border-radius: 26px; border-bottom: 1px solid var(--line); }
}
@media (orientation: landscape) and (max-height: 520px) and (min-width: 640px) {
  .capture { width: 70px; height: 70px; }
  .tile__icon { width: 44px; height: 44px; }
  .tile { width: 60px; } .tile__label { width: 60px; min-height: 0; }
  .hint { top: calc(var(--sat) + 60px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Leitor de código de barras ---------- */
.stage .bc-overlay { pointer-events: none; z-index: 2; }
.bc-panel {
  position: absolute; z-index: 5; right: calc(var(--dock-w) + var(--sar) + 10px); top: calc(var(--sat) + 70px);
  width: min(210px, 46vw); max-height: 40%; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--acid);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 0 18px rgba(57,255,20,.25);
}
.bc-panel__head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; font-size: 12px; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase; color: var(--acid); border-bottom: 1px solid var(--line);
}
.bc-panel__head b { color: #fff; }
.bc-panel__head button { font-size: 11px; color: var(--muted); text-decoration: underline; }
.bc-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; }
.bc-item { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 10px; }
.bc-item span { display: flex; flex-direction: column; min-width: 0; }
.bc-item b { font: 700 13px ui-monospace, Menlo, Consolas, monospace; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.bc-item small { font-size: 10px; color: var(--muted); }
.bc-item__rm { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; color: var(--muted); font-size: 12px; }
