:root {
  --bg: #0f172a;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --ok: #22c55e;
  --primary: #2563eb;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: linear-gradient(180deg, #0b1222, #131f3d);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.35rem;
}

.step-label {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.camera-container {
  position: relative;
  width: 100%;
  aspect-ratio: 14 / 10;
  margin-top: 14px;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 1px solid #23304f;
  max-height: 58vh;
}

.camera-container.found .scan-laser {
  opacity: 0.25;
  animation-duration: 1.1s;
}

.camera-container.captured .scan-laser {
  opacity: 0;
  animation-play-state: paused;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-guide {
  position: absolute;
  width: 88%;
  aspect-ratio: 85.6 / 53.98;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 2px dashed var(--ok);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.45);
  pointer-events: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.card-guide.found {
  border-color: #22c55e;
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.35), 0 0 0 2px rgba(34, 197, 94, 0.45) inset;
}

.card-guide.captured {
  border-color: #60a5fa;
  transform: translate(-50%, -50%) scale(1.01);
  box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.32), 0 0 0 2px rgba(96, 165, 250, 0.65) inset;
}

.overlay-text {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  text-align: center;
  font-size: 0.9rem;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  padding: 8px 10px;
}

.scan-laser {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  top: 18%;
  pointer-events: none;
  opacity: 0.9;
  background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.95), transparent);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.9), 0 0 18px rgba(34, 197, 94, 0.45);
  animation: laserScan 1.6s linear infinite;
}

@keyframes laserScan {
  0% { top: 18%; }
  50% { top: 82%; }
  100% { top: 18%; }
}

.scan-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: rgba(255, 255, 255, 0.88);
}

.scan-flash.active {
  animation: scanFlash 180ms ease-out;
}

@keyframes scanFlash {
  0% { opacity: 0; }
  30% { opacity: 0.9; }
  100% { opacity: 0; }
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 1.2rem;
  color: #fff;
  cursor: pointer;
}

.controls #captureBtn {
  grid-column: 1 / -1;
  order: 0;
}

.controls #shareBtn { order: 1; }
.controls #resetBtn { order: 2; }
.controls #autoBtn { order: 3; }
.controls #retryBtn { order: 4; }
.controls #autoBtn,
.controls #retryBtn {
  display: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary { background: var(--primary); }
.btn-auto { background: #0ea5e9; }
.btn-auto.is-on { background: #0284c7; }
.btn-auto.is-off { background: #334155; }
.btn-secondary { background: #334155; }
.btn-ghost { background: #475569; }
.btn-share { background: #16a34a; }

.status {
  margin: 6px 2px 0;
  color: #cbd5e1;
  min-height: 1.5em;
}

.send-options {
  margin-top: 4px;
  display: flex;
  gap: 14px;
  color: #cbd5e1;
  font-size: 0.9rem;
}

.send-options input {
  accent-color: #22c55e;
}

.wa-settings {
  display: none;
}

.wa-settings label {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.wa-settings input,
.wa-settings textarea {
  width: 100%;
  border: 1px solid #475569;
  border-radius: 8px;
  background: #0b1222;
  color: #e5e7eb;
  padding: 10px;
  font: inherit;
}

.wa-settings small {
  color: #94a3b8;
  font-size: 0.75rem;
  line-height: 1.5;
}

.preview-grid {
  margin-top: 2px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preview-grid figure {
  margin: 0;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid #334155;
  border-radius: 10px;
  overflow: hidden;
}

.preview-grid figcaption {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  padding: 6px;
}

.preview-grid img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
  background: #020617;
}

.site-footer {
  text-align: center;
  padding: 8px 0 18px;
}

.site-footer a {
  color: #22c55e;
  text-decoration: none;
  font-weight: 700;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(2, 6, 23, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.image-viewer.is-open {
  display: flex;
}

.image-viewer img {
  max-width: 96vw;
  max-height: 86vh;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  background: #0b1222;
}

.viewer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
  font-size: 1.1rem;
  cursor: pointer;
}
