:root {
  --black: #000;
  --ink: #0d0717;
  --violet: #7c3aed;
  --lilac: #c4a5ff;
  --white: #fff;
  --muted: #9a8fb3;
  --line: rgba(196, 165, 255, 0.22);
  --ok: #22e38a;
  --warn: #ffb020;
  --bad: #ff4466;
  --display: 'Big Shoulders Display', 'Arial Narrow', Impact, sans-serif;
  --body: 'Barlow', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background-color: var(--black);
  /* Tapiz de "M52" en contorno, como el fondo de las piezas de la disco */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='150' height='96'%3E%3Cg transform='rotate(-14 75 48)' fill='none' stroke='%23c4a5ff' stroke-opacity='.09' stroke-width='1.2' font-family='Arial Narrow,Impact,sans-serif' font-weight='700'%3E%3Ctext x='18' y='62' font-size='44'%3EM%3C/text%3E%3Ctext x='52' y='40' font-size='15'%3E52%3C/text%3E%3C/g%3E%3C/svg%3E");
  color: var(--white);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--lilac); outline-offset: 3px; }

/* ---------- Cabecera ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 20px 12px;
  max-width: 560px;
  margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 14px; }

.mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -1px;
  color: transparent;
  -webkit-text-stroke: 1.5px var(--white);
}
.mark sup {
  font-size: 16px;
  letter-spacing: 0;
  color: var(--white);
  -webkit-text-stroke: 0;
  vertical-align: top;
  position: relative;
  top: 2px;
  margin-left: 2px;
}

.brand-text {
  font-family: var(--display);
  font-weight: 300;
  font-size: 22px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lilac);
}

.demo-tag {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border: 1px solid var(--warn);
  color: var(--warn);
  border-radius: 999px;
}

main { max-width: 560px; margin: 0 auto; padding: 4px 20px 40px; }

/* ---------- Escáner ---------- */

.viewport {
  position: relative;
  aspect-ratio: 1;
  background: var(--ink);
  border: 1px solid var(--line);
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: 0 0 80px -20px var(--violet);
}

.viewport video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Esquinas del marco */
.frame { position: absolute; inset: 14%; pointer-events: none; }
.frame i {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 3px solid var(--lilac);
}
.frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

.viewport.live .frame i { border-color: var(--white); }

.idle {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.hint { margin: 0; color: var(--muted); max-width: 26ch; }
.hint.error { color: var(--bad); max-width: 32ch; }

.primary {
  font-family: var(--display);
  font-weight: 800;
  font-size: 30px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 14px 34px 12px;
  background: var(--violet);
  color: var(--white);
  border: 0;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 0 0 34px -4px var(--violet);
}
.primary:active { transform: translateY(1px); }

.secondary {
  padding: 0 18px;
  background: transparent;
  border: 1px solid var(--lilac);
  color: var(--lilac);
  font-weight: 600;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}

.ghost {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  color: var(--white);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.scan-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 12px;
  min-width: 13ch;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 999px;
  font-size: 14px;
  color: var(--white);
}
.stop { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); }

.manual { margin-top: 22px; }
.manual label { display: block; color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.manual-row { display: flex; gap: 10px; }
.manual input {
  flex: 1;
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 2px;
  font-family: var(--display);
  font-weight: 500;
  font-size: 24px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.manual input::placeholder { color: #4a3f63; }

/* ---------- Historial ---------- */

.log { margin-top: 38px; border-top: 1px solid var(--line); padding-top: 18px; }
.log-head { display: flex; align-items: baseline; justify-content: space-between; }
.log h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 300;
  font-size: 26px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.count { margin: 0; color: var(--muted); }
.count strong { color: var(--ok); font-family: var(--display); font-size: 26px; font-weight: 800; margin-right: 4px; }

.log ol { list-style: none; margin: 12px 0 0; padding: 0; }
.log li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(196, 165, 255, 0.1);
}
.log li::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--tone, var(--muted)); }
.log li .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log li .who small { display: block; color: var(--muted); font-size: 13px; }
.log li time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); margin: 14px 0 0; }
.csv { margin-top: 20px; height: 46px; }

/* ---------- Resultado ---------- */

.result {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
  background: var(--black);
  border: 10px solid var(--tone);
  overflow-y: auto;
  animation: land 180ms ease-out;
}
.result[data-result='ok'] { --tone: var(--ok); }
.result[data-result='used'] { --tone: var(--warn); }
.result[data-result='rejected'],
.result[data-result='not_found'],
.result[data-result='invalid'],
.result[data-result='error'],
.result[data-result='busy'] { --tone: var(--bad); }

@keyframes land { from { opacity: 0; transform: scale(1.03); } }

.result-body { max-width: 520px; width: 100%; margin: 0 auto; }

.verdict {
  margin: 0 0 18px;
  display: inline-block;
  padding: 6px 14px 4px;
  background: var(--tone);
  color: var(--black);
  font-family: var(--display);
  font-weight: 800;
  font-size: 30px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.1;
}

.person {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(52px, 16vw, 96px);
  line-height: 0.92;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.message { margin: 16px 0 0; font-size: 19px; color: var(--white); max-width: 30ch; }

.details { margin: 26px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 0 18px; }
.details dt, .details dd { padding: 10px 0; border-top: 1px solid var(--line); margin: 0; }
.details dt { color: var(--muted); }
.details dd { font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.result .primary { align-self: center; width: 100%; max-width: 520px; }

/* ---------- Cargando y PIN ---------- */

.loading {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.82);
  font-family: var(--display);
  font-weight: 300;
  font-size: 30px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--lilac);
}

dialog {
  background: var(--ink);
  color: var(--white);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 26px;
  width: min(340px, calc(100vw - 40px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.9); }
dialog h2 {
  margin: 0 0 16px;
  font-family: var(--display);
  font-weight: 300;
  font-size: 28px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
dialog input {
  width: 100%;
  height: 54px;
  padding: 0 14px;
  margin-bottom: 14px;
  background: var(--black);
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 24px;
  letter-spacing: 0.3em;
  text-align: center;
}
dialog .primary { width: 100%; }
.pin-error { color: var(--bad); margin: 0 0 12px; }

@media (prefers-reduced-motion: reduce) {
  .result { animation: none; }
}
