:root {
  color-scheme: dark;
  --bg: #05060a;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.68);
  --faint: rgba(255, 255, 255, 0.44);
  --hairline: rgba(255, 255, 255, 0.18);
  --glass: rgba(255, 255, 255, 0.075);
  --accent: #93c5fd;
  --accent-strong: #dbeafe;
  --tint: rgba(96, 165, 250, 0.16);
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.52);
  --radius-card: 30px;
  --radius-panel: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(30, 64, 175, 0.2), transparent 60%),
    radial-gradient(90% 60% at 110% 40%, rgba(16, 185, 129, 0.08), transparent 65%),
    radial-gradient(80% 60% at -10% 80%, rgba(245, 158, 11, 0.07), transparent 65%),
    var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

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

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Fondo ambiental
   -------------------------------------------------------------------------- */
.ambient {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  display: block;
  border-radius: 999px;
  filter: blur(80px);
  opacity: 0.5;
  will-change: transform;
}

.orb-a {
  width: 340px;
  height: 340px;
  top: -90px;
  left: -80px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.55), transparent 70%);
  animation: drift-a 19s ease-in-out infinite alternate;
}

.orb-b {
  width: 300px;
  height: 300px;
  right: -110px;
  top: 32%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.38), transparent 70%);
  animation: drift-b 23s ease-in-out infinite alternate;
}

.orb-c {
  width: 280px;
  height: 280px;
  left: 18%;
  bottom: -140px;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.3), transparent 70%);
  animation: drift-c 21s ease-in-out infinite alternate;
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.028;
  background-image: radial-gradient(rgba(255, 255, 255, 0.9) 0.5px, transparent 0.5px);
  background-size: 3px 3px;
}

@keyframes drift-a {
  to {
    transform: translate3d(38px, 46px, 0) scale(1.08);
  }
}

@keyframes drift-b {
  to {
    transform: translate3d(-42px, -34px, 0) scale(1.12);
  }
}

@keyframes drift-c {
  to {
    transform: translate3d(26px, -48px, 0) scale(1.06);
  }
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.shell {
  position: relative;
  z-index: 1;
  width: min(100%, 468px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 0 4px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  border-radius: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: #a7f3d0;
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 10px 22px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-copy strong {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-copy small {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: color 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.12);
}

.live-pill[data-connection="live"] {
  color: #d1fae5;
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(52, 211, 153, 0.28);
}

.live-pill[data-connection="live"] .live-dot {
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.14), 0 0 12px rgba(52, 211, 153, 0.75);
  animation: live-pulse 2.2s ease-in-out infinite;
}

.live-pill[data-connection="offline"] {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(251, 191, 36, 0.26);
}

.live-pill[data-connection="offline"] .live-dot {
  background: #fbbf24;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.12);
}

@keyframes live-pulse {
  50% {
    opacity: 0.55;
  }
}

/* --------------------------------------------------------------------------
   Cristal
   -------------------------------------------------------------------------- */
.glass {
  position: relative;
  border-radius: var(--radius-card);
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.035) 48%,
    rgba(255, 255, 255, 0.06)
  );
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  overflow: hidden;
}

.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.48),
    rgba(255, 255, 255, 0.06) 38%,
    rgba(255, 255, 255, 0.02) 100%
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Tarjeta / estados
   -------------------------------------------------------------------------- */
.ticket {
  --accent: #93c5fd;
  --accent-strong: #dbeafe;
  --tint: rgba(96, 165, 250, 0.17);
  padding: 22px;
  animation: card-in 0.75s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: box-shadow 0.6s ease;
}

.ticket[data-state="loading"] {
  --accent: #94a3b8;
  --accent-strong: #e2e8f0;
  --tint: rgba(148, 163, 184, 0.13);
}

.ticket[data-state="none"] {
  --accent: #93c5fd;
  --accent-strong: #dbeafe;
  --tint: rgba(96, 165, 250, 0.17);
}

.ticket[data-state="inside"] {
  --accent: #34d399;
  --accent-strong: #d1fae5;
  --tint: rgba(16, 185, 129, 0.21);
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.52), 0 0 46px rgba(16, 185, 129, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.ticket[data-state="return"] {
  --accent: #fbbf24;
  --accent-strong: #fef3c7;
  --tint: rgba(245, 158, 11, 0.21);
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.52), 0 0 46px rgba(245, 158, 11, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.ticket[data-state="stale"] {
  --accent: #cbd5e1;
  --accent-strong: #f1f5f9;
  --tint: rgba(148, 163, 184, 0.13);
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ticket-tint {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 78% at 50% 0%, var(--tint), transparent 64%),
    radial-gradient(90% 60% at 50% 110%, var(--tint), transparent 70%);
  opacity: 0.95;
  transition: background 0.7s ease;
  pointer-events: none;
}

.ticket-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.event-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

.event-block h2 {
  margin: 0;
  max-width: 250px;
  font-size: 21px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: #fff;
  overflow-wrap: anywhere;
}

.state-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: color 0.4s ease, background 0.4s ease, border-color 0.4s ease;
  white-space: nowrap;
}

.state-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

/* Fallback para navegadores sin color-mix */
@supports not (background: color-mix(in srgb, white 10%, transparent)) {
  .state-pill {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
  }
}

/* --------------------------------------------------------------------------
   QR
   -------------------------------------------------------------------------- */
.qr-stage {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
}

.qr-frame {
  position: relative;
  width: min(100%, 316px);
  aspect-ratio: 1 / 1;
  padding: 22px;
  border-radius: 24px;
  background: #ffffff;
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.62) inset;
  overflow: hidden;
}

.qr-code {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.qr-code canvas,
.qr-code img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  border-radius: 6px;
  image-rendering: pixelated;
}

.qr-code img {
  object-fit: contain;
}

.qr-code-fallback {
  margin: 0;
  padding: 16px;
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 600;
  color: #0f172a;
}

.qr-skeleton {
  position: absolute;
  inset: 22px;
  border-radius: 12px;
  background: #f1f5f9;
  overflow: hidden;
}

.qr-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.9), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
}

.qr-frame.qr-ready .qr-skeleton {
  display: none;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.qr-caption {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.55);
}

.qr-caption-dot {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

/* --------------------------------------------------------------------------
   Estado textual
   -------------------------------------------------------------------------- */
.status {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-top: 20px;
}

.status-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 12px;
  border-radius: 18px;
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 12px 24px rgba(0, 0, 0, 0.22);
  transition: color 0.4s ease, background 0.4s ease, border-color 0.4s ease;
}

@supports not (background: color-mix(in srgb, white 10%, transparent)) {
  .status-icon {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
  }
}

.status-icon svg {
  width: 27px;
  height: 27px;
}

.status h1 {
  margin: 0;
  font-size: clamp(28px, 8.2vw, 36px);
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: #fff;
  text-wrap: balance;
}

.status p {
  max-width: 320px;
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.55;
  font-weight: 450;
  color: var(--muted);
  text-wrap: pretty;
}

.ticket.state-change .status-icon {
  animation: state-pop 0.55s cubic-bezier(0.22, 1.4, 0.36, 1);
}

@keyframes state-pop {
  0% {
    transform: scale(0.82);
    opacity: 0.4;
  }
  60% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Metadatos
   -------------------------------------------------------------------------- */
.meta {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 22px 0 0;
  padding: 0;
}

.meta > div {
  min-width: 0;
  padding: 11px 13px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.meta dt {
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.meta dd {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.2;
  font-weight: 650;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tnum {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.privacy {
  position: relative;
  z-index: 1;
  margin: 18px 2px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 10.5px;
  line-height: 1.45;
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
}

/* --------------------------------------------------------------------------
   Error
   -------------------------------------------------------------------------- */
.error-card {
  --accent: #f87171;
  --tint: rgba(239, 68, 68, 0.18);
  padding: 30px 24px;
  text-align: center;
  background: linear-gradient(145deg, rgba(239, 68, 68, 0.13), rgba(255, 255, 255, 0.035));
  border-color: rgba(248, 113, 113, 0.28);
  animation: card-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.error-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 18px;
  font-size: 24px;
  font-weight: 800;
  color: #fecaca;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(248, 113, 113, 0.32);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.error-card h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.error-card p {
  max-width: 330px;
  margin: 10px auto 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.error-card .error-hint {
  margin-top: 14px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 18px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.32);
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 10;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 13px;
  text-align: center;
  color: #fff;
  background: rgba(239, 68, 68, 0.9);
}

/* --------------------------------------------------------------------------
   Responsive y accesibilidad
   -------------------------------------------------------------------------- */
@media (max-width: 360px) {
  .shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .ticket {
    padding: 18px;
    border-radius: 26px;
  }

  .state-pill {
    padding: 0 9px;
    font-size: 9px;
  }

  .event-block h2 {
    font-size: 19px;
  }

  .qr-frame {
    padding: 14px;
    border-radius: 21px;
  }

  .qr-skeleton {
    inset: 14px;
  }
}

@media (min-width: 520px) and (min-height: 760px) {
  .shell {
    padding-top: 36px;
    padding-bottom: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .orb {
    filter: blur(80px);
  }
}

@media (prefers-contrast: more) {
  .glass {
    border-color: rgba(255, 255, 255, 0.5);
  }

  .status p,
  .qr-caption,
  .privacy {
    color: rgba(255, 255, 255, 0.86);
  }
}
