/* ==========================================================================
   gate.css — TOKENSNIPE ref gate
   --------------------------------------------------------------------------
   The gate lives in the same document as the page now (one index.html serves
   both "/" and "/ref/<code>"), so it sits over the page as a semi-transparent,
   softly blurred layer. The page is the background: its glow and shapes stay
   visible, but nothing behind the card can be clicked until a code is accepted.

   Loaded AFTER style.css on purpose — the tokens below are style.css's own
   (--accent #A69AF5, --border, --text-primary, --font-mono, …), so the card
   looks native to the dark workstation theme without duplicating any colour.

   Everything is namespaced .vf-* / #vf-gate so it cannot collide with the
   site stylesheet.
   ========================================================================== */

/* ------------------------------------------------------------------ shell -- */

.vf-gate {
  --vf-ink: var(--text-primary, #f1f2f4);
  --vf-soft: var(--text-secondary, #a1a8b3);
  --vf-line: var(--border, #2b3039);
  --vf-accent: var(--accent, #a69af5);
  --vf-red: var(--danger, #f87171);
  --vf-delay: 900ms;

  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3.5vw, 40px);
  overflow-y: auto;
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  color: var(--vf-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.vf-gate[hidden] { display: none; }

/* The scrim is the semi-transparent part: a light wash plus a soft blur, so the
   page stays readable-ish behind the card — visible, but clearly not the focus. */
.vf-gate__scrim {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(166, 154, 245, 0.05), transparent 60%),
    rgba(5, 6, 8, 0.3);
  -webkit-backdrop-filter: blur(3px) saturate(0.95);
  backdrop-filter: blur(3px) saturate(0.95);
  animation: vf-fade 0.4s ease both;
}

/* one quiet accent bloom behind the card, tied to the theme accent */
.vf-gate__scrim::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(760px, 130vw);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(166, 154, 245, 0.18), transparent 62%);
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--vf-accent) 24%, transparent),
    transparent 62%
  );
  filter: blur(30px);
  opacity: 0.5;
  pointer-events: none;
}

/* Browsers that cannot blur get a heavier wash instead of a see-through one. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .vf-gate__scrim { background: rgba(5, 6, 8, 0.68); }
  .vf-gate__card { background: #15181d; }
}

/* ------------------------------------------------------------------- card -- */

.vf-gate__card {
  position: relative;
  z-index: 1;
  width: min(452px, 100%);
  max-height: calc(100vh - 2 * clamp(14px, 3.5vw, 40px));
  max-height: calc(100dvh - 2 * clamp(14px, 3.5vw, 40px));
  margin: auto;
  padding: 24px 26px 20px;
  overflow: hidden auto;
  border: 1px solid var(--vf-line);
  border-radius: 12px;
  background: rgba(21, 24, 29, 0.88);
  -webkit-backdrop-filter: blur(14px) saturate(1.05);
  backdrop-filter: blur(14px) saturate(1.05);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 40px 90px -34px rgba(0, 0, 0, 0.9),
    0 10px 30px -18px rgba(0, 0, 0, 0.7);
  animation: vf-rise 0.52s cubic-bezier(0.16, 1, 0.3, 1) both;
  scrollbar-width: thin;
  scrollbar-color: var(--vf-line) transparent;
}

.vf-gate__card:focus { outline: none; }

/* hairline accent at the top edge */
.vf-gate__card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, var(--vf-accent), transparent 62%);
  opacity: 0.9;
  pointer-events: none;
}

.vf-gate__card::-webkit-scrollbar { width: 8px; }
.vf-gate__card::-webkit-scrollbar-thumb { background: var(--vf-line); border-radius: 99px; }
.vf-gate__card::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------- head -- */

.vf-gate__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 30px;
}

.vf-gate__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 500 9.5px/1 var(--font-mono, ui-monospace, SFMono-Regular, Consolas, monospace);
  letter-spacing: 1.7px;
  text-transform: uppercase;
  color: var(--vf-soft);
  white-space: nowrap;
}

.vf-gate__brand img {
  width: 16px;
  height: 16px;
  display: block;
  opacity: 0.9;
}

.vf-gate__brand b {
  color: var(--vf-accent);
  font-weight: 500;
}

.vf-gate__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--vf-line);
  border-radius: 999px;
  font: 500 8.5px/1 var(--font-mono, ui-monospace, Consolas, monospace);
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: var(--vf-accent);
  white-space: nowrap;
}

.vf-gate__status i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: vf-pulse 2.6s ease-in-out infinite;
}

/* ------------------------------------------------------------------- copy -- */

.vf-gate__eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font: 500 9px/1 var(--font-mono, ui-monospace, Consolas, monospace);
  letter-spacing: 1.7px;
  text-transform: uppercase;
  color: var(--vf-accent);
}

.vf-gate__eyebrow::before {
  content: '';
  width: 18px;
  height: 1px;
  background: currentColor;
  opacity: 0.7;
}

.vf-gate__title {
  margin: 0 0 10px;
  font-size: clamp(27px, 3.3vw, 33px);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -1.2px;
  color: var(--vf-ink);
}

.vf-gate__title em {
  font-style: normal;
  color: var(--vf-accent);
}

.vf-gate__copy {
  margin: 0 0 24px;
  max-width: 36ch;
  font-size: 13px;
  line-height: 1.62;
  color: var(--vf-soft);
}

/* ------------------------------------------------------------------- form -- */

.vf-gate__form { margin: 0; }

.vf-gate__label {
  display: block;
  margin-bottom: 8px;
  font: 500 9px/1 var(--font-mono, ui-monospace, Consolas, monospace);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--vf-soft);
}

.vf-gate__field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 5px 5px 14px;
  border: 1px solid var(--vf-line);
  border-radius: 8px;
  background: rgba(27, 31, 38, 0.55);
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.vf-gate__field:focus-within {
  border-color: var(--vf-accent);
  background: var(--surface-elevated, #1b1f26);
  box-shadow: 0 0 0 3px rgba(166, 154, 245, 0.2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--vf-accent) 22%, transparent);
}

.vf-gate__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--vf-ink);
  font: 500 13.5px/1 var(--font-mono, ui-monospace, SFMono-Regular, Consolas, monospace);
  letter-spacing: 0.6px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.vf-gate__input:focus,
.vf-gate__input:focus-visible { outline: none; }

.vf-gate__input::placeholder {
  color: var(--vf-soft);
  opacity: 0.55;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.vf-gate__input:-webkit-autofill,
.vf-gate__input:-webkit-autofill:hover,
.vf-gate__input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--vf-ink);
  -webkit-box-shadow: 0 0 0 60px rgba(13, 15, 18, 0.01) inset;
  transition: background-color 9999s ease-out 0s;
}

.vf-gate__submit {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--primary-btn-bg, #c0b5ff);
  color: var(--primary-btn-text, #0d0f12);
  font: 600 12px/1 var(--font-sans, -apple-system, 'Segoe UI', sans-serif);
  letter-spacing: 0.1px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, opacity 0.18s,
    transform 0.12s;
}

.vf-gate__submit span {
  font-size: 13px;
  opacity: 0.75;
  transition: transform 0.18s;
}

.vf-gate__submit:hover { background: var(--primary-btn-hover, #d2cbff); }
.vf-gate__submit:hover span { transform: translate(1px, -1px); }
.vf-gate__submit:active { transform: translateY(1px); }
.vf-gate__submit:disabled { opacity: 0.7; cursor: default; }
.vf-gate__submit:focus-visible {
  outline: 2px solid var(--vf-accent);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------- message -- */

.vf-gate__msg {
  min-height: 16px;
  margin: 10px 0 0;
  font: 500 10px/1.45 var(--font-mono, ui-monospace, Consolas, monospace);
  letter-spacing: 0.3px;
  color: var(--vf-soft);
}

.vf-gate__msg.is-err { color: var(--vf-red); }
.vf-gate__msg.is-ok { color: var(--vf-accent); }

/* -------------------------------------------------------------------- foot -- */

.vf-gate__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--vf-line);
  font: 400 9.5px/1.5 var(--font-mono, ui-monospace, Consolas, monospace);
  letter-spacing: 0.2px;
  color: var(--vf-soft);
}

.vf-gate__foot code {
  color: var(--vf-ink);
  font-family: inherit;
}

.vf-gate__foot span:last-child { text-align: right; }

/* ---------------------------------------------------------------- progress -- */

.vf-gate__progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}

.vf-gate__progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--vf-accent);
}

.vf-gate.is-ok .vf-gate__progress { opacity: 1; }
.vf-gate.is-ok .vf-gate__progress i { animation: vf-progress var(--vf-delay) linear forwards; }

/* ----------------------------------------------------------------- states -- */

.vf-gate.is-ok .vf-gate__field {
  border-color: var(--vf-accent);
  background: transparent;
}

.vf-gate.is-ok .vf-gate__submit {
  background: var(--vf-accent);
  border-color: var(--vf-accent);
  color: #0d0f12;
}

.vf-gate.is-err .vf-gate__field {
  border-color: var(--vf-red);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.16);
}

.vf-gate.is-err .vf-gate__card {
  animation: vf-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.vf-gate.is-out {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

/* --------------------------------------------------------------- animation -- */

@keyframes vf-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes vf-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes vf-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes vf-progress {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes vf-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* ---------------------------------------------------------------- responsive -- */

@media (max-width: 520px) {
  .vf-gate { padding: 12px; }

  .vf-gate__card {
    padding: 20px 18px 16px;
    border-radius: 12px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }

  .vf-gate__top { margin-bottom: 24px; }
  .vf-gate__title { font-size: 26px; letter-spacing: -0.8px; }
  .vf-gate__copy { margin-bottom: 20px; font-size: 12.5px; }
  .vf-gate__eyebrow { margin-bottom: 12px; }

  .vf-gate__field {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  .vf-gate__input { height: 38px; padding: 0 4px; }
  .vf-gate__submit { width: 100%; height: 42px; }

  .vf-gate__foot {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .vf-gate__foot span:last-child { text-align: left; }
}

@media (max-height: 560px) and (min-width: 521px) {
  .vf-gate { padding: 12px; }
  .vf-gate__card {
    padding: 18px 22px 14px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
  }
  .vf-gate__top { margin-bottom: 16px; }
  .vf-gate__eyebrow { margin-bottom: 10px; }
  .vf-gate__title { font-size: 25px; letter-spacing: -0.8px; }
  .vf-gate__copy { margin-bottom: 14px; font-size: 12px; line-height: 1.5; }
  .vf-gate__foot { margin-top: 12px; padding-top: 10px; font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .vf-gate,
  .vf-gate *,
  .vf-gate *::before,
  .vf-gate *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------------------
   One page, two URLs.

   The gate is markup in index.html, and the same file is served at "/" and at
   "/ref/<code>". A tiny script in <head> adds .vf-gated to <html> on every path
   that is not a ref page, before the gate markup is parsed — so "/" shows the
   card from the first paint and "/ref/<code>" never flashes it. No JavaScript
   means no .vf-gated, so the page stays readable instead of presenting a card
   that cannot work.
   --------------------------------------------------------------------------- */
html:not(.vf-gated) .vf-gate {
  display: none !important;
}
