* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-dark: #050816;
  --bg-card: rgba(10, 18, 38, 0.88);
  --cyan: #20e3ff;
  --violet: #8f5cff;
  --pink: #ff4fd8;
  --text: #ffffff;
  --muted: #aeb8d4;
}

html,
body {
  margin: 0;
  min-height: 100svh;
  font-family: Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(
      circle at top left,
      rgba(32, 227, 255, 0.2),
      transparent 34%
    ),
    radial-gradient(
      circle at bottom right,
      rgba(143, 92, 255, 0.24),
      transparent 42%
    ),
    var(--bg-dark);
  overflow-x: hidden;
}

.background-neurons {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(
      120deg,
      transparent 0 48%,
      rgba(32, 227, 255, 0.34) 49%,
      transparent 50%
    ),
    radial-gradient(circle, rgba(32, 227, 255, 0.8) 2px, transparent 3px);
  background-size:
    84px 84px,
    52px 52px;
  animation: floatNeurons 18s linear infinite;
}

@keyframes floatNeurons {
  to {
    transform: translateY(-80px);
  }
}

.app {
  position: relative;
  width: 100%;
  max-width: 430px;
  min-height: 100svh;
  margin: 0 auto;
  padding: 10px 10px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

.hero {
  text-align: center;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  padding: 5px 11px;
  border: 1px solid rgba(32, 227, 255, 0.45);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(32, 227, 255, 0.08);
  font-size: 11px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

h1 {
  margin: 7px 0 3px;
  font-size: clamp(22px, 6.6vw, 30px);
  line-height: 1;
  background: linear-gradient(90deg, var(--cyan), var(--violet), var(--pink));
  -webkit-background-clip: text;
  color: transparent;
}

.hero p {
  margin: 0 auto;
  max-width: 320px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.camera-card {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 7px;
  border-radius: 22px;
  background:
    linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
    linear-gradient(135deg, var(--cyan), var(--violet), var(--pink)) border-box;
  border: 1px solid transparent;
  box-shadow:
    0 0 18px rgba(32, 227, 255, 0.16),
    0 18px 42px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

.camera-card:has(video:not([hidden])) .empty-state,
.camera-card:has(#resultImage:not([hidden])) .empty-state {
  display: none;
}

video,
#resultImage {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  max-height: calc(100svh - 190px);
  display: block;
  object-fit: contain;
  border-radius: 17px;
  background: #000;
}

canvas {
  display: none;
}

.empty-state {
  position: relative;
  z-index: 1;
  height: 100%;
  min-height: 260px;
  max-height: calc(100svh - 190px);
  border-radius: 17px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  background:
    radial-gradient(circle, rgba(32, 227, 255, 0.13), transparent 40%),
    rgba(255, 255, 255, 0.04);
}

.brain-icon {
  font-size: 46px;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 14px rgba(32, 227, 255, 0.55));
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

.scan-line {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 10px;
  height: 2px;
  z-index: 4;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: scan 3s ease-in-out infinite;
  opacity: 0.6;
}

@keyframes scan {
  50% {
    transform: translateY(calc(100svh - 250px));
  }
}

/* Botón flotante moderno para cambiar cámara */
.camera-switch {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 20;

  width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;

  background:
    linear-gradient(
      145deg,
      rgba(255, 255, 255, 0.22),
      rgba(255, 255, 255, 0.06)
    ),
    rgba(5, 8, 22, 0.48);

  color: white;

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.35),
    inset 0 1px 1px rgba(255, 255, 255, 0.22),
    0 0 18px rgba(32, 227, 255, 0.16);

  transition:
    transform 0.18s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.camera-switch::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  padding: 1px;
  background: linear-gradient(135deg, var(--cyan), var(--violet), var(--pink));
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
  -webkit-mask-composite: xor;
  opacity: 0.8;
}

.camera-icon {
  font-size: 22px;
  transform: translateY(-1px);
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.35));
}

.switch-icon {
  position: absolute;
  right: 8px;
  bottom: 7px;

  width: 17px;
  height: 17px;

  display: grid;
  place-items: center;

  border-radius: 50%;
  background: var(--cyan);
  color: #04101c;

  font-size: 12px;
  font-weight: 900;
  line-height: 1;

  box-shadow: 0 0 10px rgba(32, 227, 255, 0.65);
}

.camera-switch:active {
  transform: scale(0.92) rotate(25deg);
}

.camera-switch[hidden] {
  display: none;
}

.actions {
  flex-shrink: 0;
  margin-top: 9px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

button,
a {
  width: 100%;
  min-height: 44px;
  padding: 11px 14px;
  border: none;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: white;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(32, 227, 255, 0.18);
}

#downloadBtn {
  background: linear-gradient(135deg, #2cff9a, #20e3ff);
  color: #02121c;
}

button:active,
a:active {
  transform: scale(0.98);
}

button[hidden],
a[hidden],
video[hidden],
#resultImage[hidden] {
  display: none;
}

@media (max-height: 740px) {
  .badge,
  .hero p {
    display: none;
  }

  .hero {
    margin-bottom: 7px;
  }

  h1 {
    margin: 2px 0 0;
    font-size: 23px;
  }

  video,
  #resultImage,
  .empty-state {
    max-height: calc(100svh - 142px);
  }

  .actions {
    gap: 7px;
    margin-top: 7px;
  }

  button,
  a {
    min-height: 41px;
    padding: 9px 12px;
    font-size: 14px;
    border-radius: 13px;
  }

  .camera-switch {
    width: 48px;
    height: 48px;
    min-height: 48px;
    top: 13px;
    right: 13px;
  }

  .camera-icon {
    font-size: 20px;
  }
}

@media (max-height: 650px) {
  h1 {
    display: none;
  }

  .app {
    padding-top: 7px;
  }

  video,
  #resultImage,
  .empty-state {
    max-height: calc(100svh - 115px);
  }
}

@media (max-width: 360px) {
  .app {
    padding-inline: 8px;
  }

  .camera-card {
    padding: 6px;
    border-radius: 19px;
  }

  video,
  #resultImage,
  .empty-state {
    border-radius: 14px;
  }

  .camera-switch {
    width: 46px;
    height: 46px;
    min-height: 46px;
  }
}
