:root {
  /* Matches cardfest-expo-landing Tailwind theme tokens. */
  --bg: #0a1624;
  --bg-2: #0e1d30;
  --navy: #183454;
  --card: #111f33;
  --border: #1e3350;
  --text: #e8eef6;
  --muted: #93a4bd;
  --green: #3fae63;
  --brand-green: #628f66;
  --amber: #dcab4b;
  --gold: #dcab4b;
  --red: #e2574c;
  --blue: #2b6592;
  --radius: 16px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-hype: "Bebas Neue", Impact, Haettenschweiler, sans-serif;
  font-family: var(--font-sans);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ------------------------------- screens ------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* -------------------------------- PIN ---------------------------------- */
#pin-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(
      900px 480px at 50% -8%,
      rgba(220, 171, 75, 0.12),
      transparent 55%
    ),
    radial-gradient(1200px 600px at 50% -10%, var(--navy), var(--bg) 65%);
}

.card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(220, 171, 75, 0.08);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  text-align: center;
}

.brand-logo {
  width: min(200px, 72%);
  height: auto;
  display: block;
  filter: drop-shadow(0 0 14px rgba(220, 171, 75, 0.4));
}

.brand-sub {
  font-family: var(--font-hype);
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--gold);
}

.title {
  font-family: var(--font-hype);
  font-size: 32px;
  letter-spacing: 1px;
  margin: 0 0 6px;
  font-weight: 400;
}

.subtitle {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 18px;
  padding: 14px 16px;
  outline: none;
}

.input:focus {
  border-color: var(--blue);
}

.remember {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 14px 2px 4px;
}

.remember input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  padding: 15px 16px;
  margin-top: 16px;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--blue));
  color: #0a1624;
  box-shadow: 0 8px 24px rgba(220, 171, 75, 0.25);
}

.btn-secondary {
  background: var(--blue);
  color: #04121d;
  margin-top: 10px;
}

.btn-light {
  background: rgba(255, 255, 255, 0.92);
  color: #0a1624;
}

.btn:active {
  transform: translateY(1px);
}

.error {
  color: var(--red);
  font-size: 13px;
  margin: 12px 0 0;
}

.api-line {
  color: var(--muted);
  font-size: 11px;
  margin: 18px 0 0;
  word-break: break-all;
}

/* ------------------------------ scanner -------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-logo {
  height: 34px;
  width: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(220, 171, 75, 0.35));
}

.topbar-text {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.ok {
  background: var(--green);
}

.dot.err {
  background: var(--red);
}

.topbar-right {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reticle {
  position: absolute;
  width: min(66vw, 300px);
  height: min(66vw, 300px);
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid var(--gold);
  box-shadow: 0 0 12px rgba(220, 171, 75, 0.35);
}

.corner.tl {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
  border-radius: 8px 0 0 0;
}
.corner.tr {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
  border-radius: 0 8px 0 0;
}
.corner.bl {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
  border-radius: 0 0 0 8px;
}
.corner.br {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
  border-radius: 0 0 8px 0;
}

.hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  margin: 0;
  padding: 0 20px;
}

.manual {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
}

.manual summary {
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  list-style: none;
}

.manual summary::-webkit-details-marker {
  display: none;
}

.manual form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.manual .input {
  font-size: 15px;
  padding: 12px 14px;
}

.manual .btn {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
  padding: 12px 18px;
}

/* ------------------------------ result --------------------------------- */
.result {
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: background-color 0.15s ease;
  overflow: hidden;
}

.result-logo {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  width: 96px;
  height: auto;
  opacity: 0.92;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.25));
  z-index: 2;
  pointer-events: none;
}

.result[data-state="redeemed"] {
  background: var(--green);
  color: #05210f;
}
.result[data-state="already"] {
  background: var(--amber);
  color: #2a1e02;
}
.result[data-state="invalid"],
.result[data-state="voided"] {
  background: var(--red);
  color: #2a0906;
}
.result[data-state="error"] {
  background: var(--bg-2);
  color: var(--text);
}

.result-note {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.35);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.result-note::before {
  content: "Note";
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
  margin-bottom: 4px;
}

.result-inner {
  width: 100%;
  max-width: 420px;
  text-align: center;
  position: relative;
  z-index: 1;
}

.result-icon {
  font-size: 84px;
  line-height: 1;
  font-weight: 800;
  margin-bottom: 12px;
  display: inline-block;
  transform-origin: center;
}

.result-title {
  font-family: var(--font-hype);
  font-size: 42px;
  letter-spacing: 1px;
  margin: 0 0 6px;
  font-weight: 400;
}

.result-product {
  font-size: 22px;
  font-weight: 700;
  margin: 4px 0;
}

.result-detail {
  font-size: 15px;
  opacity: 0.85;
  margin: 6px 0 0;
}

.result-token {
  font-size: 12px;
  opacity: 0.7;
  margin: 14px 0 0;
  word-break: break-all;
}

.result .btn-light {
  margin-top: 28px;
}

/* Result entrance animations (restarted via .result-anim on each scan). */
@keyframes result-flash-in {
  0% { filter: brightness(1.45); }
  100% { filter: brightness(1); }
}

@keyframes icon-pop {
  0% { transform: scale(0.2); opacity: 0; }
  55% { transform: scale(1.22); opacity: 1; }
  75% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

@keyframes icon-wiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  15% { transform: rotate(-14deg) scale(1.08); }
  30% { transform: rotate(12deg) scale(1.08); }
  45% { transform: rotate(-8deg) scale(1.04); }
  60% { transform: rotate(6deg) scale(1.02); }
  75% { transform: rotate(-3deg) scale(1); }
}

@keyframes icon-deny {
  0% { transform: scale(0.4) rotate(-20deg); opacity: 0; }
  40% { transform: scale(1.18) rotate(8deg); opacity: 1; }
  55% { transform: translateX(-10px) rotate(-4deg); }
  70% { transform: translateX(10px) rotate(4deg); }
  85% { transform: translateX(-5px); }
  100% { transform: translateX(0) rotate(0) scale(1); }
}

@keyframes copy-rise {
  0% { transform: translateY(14px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes pulse-ring {
  0% { transform: scale(0.55); opacity: 0.55; }
  100% { transform: scale(1.65); opacity: 0; }
}

.result.result-anim[data-state="redeemed"],
.result.result-anim[data-state="already"],
.result.result-anim[data-state="invalid"],
.result.result-anim[data-state="voided"],
.result.result-anim[data-state="error"] {
  animation: result-flash-in 0.45s ease-out;
}

.result.result-anim[data-state="redeemed"] .result-icon {
  animation: icon-pop 0.55s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.result.result-anim[data-state="already"] .result-icon {
  animation: icon-wiggle 0.65s ease-out;
}

.result.result-anim[data-state="invalid"] .result-icon,
.result.result-anim[data-state="voided"] .result-icon,
.result.result-anim[data-state="error"] .result-icon {
  animation: icon-deny 0.55s ease-out;
}

.result.result-anim .result-title,
.result.result-anim .result-product,
.result.result-anim .result-detail,
.result.result-anim .result-note {
  animation: copy-rise 0.4s ease-out both;
}
.result.result-anim .result-product { animation-delay: 0.06s; }
.result.result-anim .result-detail { animation-delay: 0.12s; }
.result.result-anim .result-note { animation-delay: 0.16s; }

/* Expanding ring behind success / warning icons. */
.result.result-anim[data-state="redeemed"] .result-inner::before,
.result.result-anim[data-state="already"] .result-inner::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 42px; /* center of the 84px icon */
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  border-radius: 50%;
  border: 3px solid currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  animation: pulse-ring 0.7s ease-out 0.05s both;
}

.result.result-anim[data-state="redeemed"] .result-inner::before {
  border-color: rgba(5, 33, 15, 0.35);
}
.result.result-anim[data-state="already"] .result-inner::before {
  border-color: rgba(42, 30, 2, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .result.result-anim,
  .result.result-anim .result-icon,
  .result.result-anim .result-title,
  .result.result-anim .result-product,
  .result.result-anim .result-detail,
  .result.result-anim .result-note,
  .result.result-anim .result-inner::before {
    animation: none !important;
  }
}
