/* ══════════════════════════════════════════════════════════════════
   BytePatch AR card — interface chrome around the A-Frame canvas.
   The 3D layer owns the middle of the screen; everything here frames it.
   ══════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'JetBrains Mono';
  src: url('vendor/fonts/jetbrains-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('vendor/fonts/jetbrains-mono-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --red: #d6161f;
  --red-hot: #ff2a35;
  --ink: #0b0b0d;
  --ink-2: #141417;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f2f2f4;
  --muted: #9a9aa2;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  overscroll-behavior: none;
}

/* Once the feed is live nothing behind it should be painted at all. Belt and
   braces alongside the video z-index fix above.
   Two separate rules on purpose, and no :has(): a comma-separated list is
   discarded wholesale if any selector in it fails to parse, so pairing these
   with a modern selector would silently disable both on older browsers. The
   class is set on <html> and <body> from JS instead. */
html.ar-live {
  background: transparent;
}

body.ar-live {
  background: transparent;
}

/* The WebGL canvas must stay transparent or it hides the feed it sits on.
   The renderer is created with alpha:true, but A-Frame also injects its own
   stylesheet, so this pins it. */
.a-canvas,
a-scene canvas {
  background: transparent !important;
}

/* Stacking, bottom to top: camera feed, code rain, 3D overlay, interface. */
a-scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 2;
}

/* MindAR injects the camera <video> into <body> and sets z-index:-2 inline.
   That is the whole reason the feed can go missing: a negative z-index paints
   in the layer *before* in-flow block descendants, and body's own opaque
   background box is one of those — so the video renders and is then covered by
   it. The override has to be !important to beat the inline style.

   Sizing is left to MindAR: its _resize() computes cover dimensions and centres
   the feed with negative margins. Adding inset/object-fit on top only
   over-constrains it. */
video {
  position: fixed !important;
  top: 0;
  left: 0;
  z-index: 0 !important;
}

#bg-fx {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.55s ease;
}

#bg-fx.on {
  opacity: 1;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#ui > * {
  pointer-events: auto;
}

/* ─────────────────────── Full-screen panels ─────────────────────── */

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(28px + var(--safe-t)) 24px calc(28px + var(--safe-b));
  background: radial-gradient(120% 90% at 50% 0%, #1a0508 0%, var(--ink) 62%);
  z-index: 20;
}

.screen[hidden] {
  display: none;
}

/* The camera stream is live well before MindAR finishes parsing its targets, so
   the loading screen must not hide it — otherwise the whole start-up reads as a
   blank page. Translucent, with the feed showing through. */
#loading {
  background: rgba(11, 11, 13, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.intro-inner {
  width: min(430px, 100%);
  text-align: center;
}

.intro-mark {
  width: 92px;
  height: 92px;
  object-fit: contain;
  filter: drop-shadow(0 0 22px rgba(214, 22, 31, 0.55));
  animation: breathe 4.5s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-6px) scale(1.03);
  }
}

#intro h1 {
  margin: 14px 0 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.6px;
}

#intro h1 span {
  color: var(--red);
}

.kicker {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  margin: 22px auto 26px;
  max-width: 34ch;
  font-size: 15px;
  line-height: 1.6;
  color: #c9c9d0;
}

button,
.act {
  font-family: var(--mono);
  cursor: pointer;
}

#start,
#retry {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 15px 30px;
  border: 1px solid rgba(255, 60, 70, 0.5);
  border-radius: 999px;
  background: linear-gradient(180deg, #d6161f, #93060d);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.4px;
  box-shadow: 0 10px 34px rgba(214, 22, 31, 0.38);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#start:active,
#retry:active {
  transform: scale(0.97);
  box-shadow: 0 5px 18px rgba(214, 22, 31, 0.3);
}

#start .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.75);
  animation: ping 1.8s ease-out infinite;
}

@keyframes ping {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(255, 255, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.fineprint {
  margin: 16px auto 0;
  max-width: 36ch;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  color: #6f6f78;
}

.fineprint a {
  color: #b8b8c2;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ───────────────────────────── Loading ───────────────────────────── */

.loader {
  text-align: center;
}

.loader-ring {
  width: 54px;
  height: 54px;
  margin: 0 auto 20px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#loading-text {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

#loading-text::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0% {
    content: '';
  }
  25% {
    content: '.';
  }
  50% {
    content: '..';
  }
  75% {
    content: '...';
  }
}

/* ──────────────────────── Scanning reticle ──────────────────────── */

#scanning {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 26px;
  z-index: 12;
  pointer-events: none;
  background: radial-gradient(60% 45% at 50% 45%, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
}

#scanning[hidden] {
  display: none;
}

.reticle {
  position: relative;
  width: min(74vw, 340px);
  aspect-ratio: 90 / 50;
  border-radius: 10px;
  overflow: hidden;
}

.reticle .c {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2.5px solid var(--red-hot);
  filter: drop-shadow(0 0 6px rgba(255, 42, 53, 0.8));
  animation: cornerPulse 2s ease-in-out infinite;
}

.reticle .tl {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 8px;
}
.reticle .tr {
  top: 0;
  right: 0;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 8px;
}
.reticle .bl {
  bottom: 0;
  left: 0;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 8px;
}
.reticle .br {
  bottom: 0;
  right: 0;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 8px;
}

@keyframes cornerPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.reticle-beam {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--red-hot), transparent);
  box-shadow: 0 0 18px 3px rgba(255, 42, 53, 0.6);
  animation: sweep 2.4s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

@keyframes sweep {
  0% {
    top: 4%;
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  88% {
    opacity: 1;
  }
  100% {
    top: 96%;
    opacity: 0;
  }
}

.scan-text {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #dcdce2;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9);
}

/* ─────────────────────────── Action bar ─────────────────────────── */

#hud {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 14;
  padding: 14px 12px calc(14px + var(--safe-b));
  background: linear-gradient(180deg, transparent, rgba(6, 6, 8, 0.82) 42%);
  transform: translateY(12px);
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

#hud[hidden] {
  display: none;
}

#hud.on {
  transform: translateY(0);
  opacity: 1;
}

.hud-id {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 2.6px;
  text-transform: uppercase;
  color: #d8d8de;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #29d17c;
  box-shadow: 0 0 10px #29d17c;
  animation: cornerPulse 1.6s ease-in-out infinite;
}

.hud-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
  max-width: 620px;
  margin: 0 auto;
}

@media (max-width: 400px) {
  .hud-actions {
    gap: 4px;
  }
  .act {
    padding: 10px 2px 9px;
    font-size: 9px;
    letter-spacing: 0;
  }
  .act svg {
    width: 19px;
    height: 19px;
  }
}

.act {
  flex: 1 1 0;
  min-width: 0;
  /* Six actions on a 360 px phone leaves ~54 px each — keep the tap target at
     the 44 px minimum even when the label has to shrink. */
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 11px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(20, 20, 23, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 10px;
  letter-spacing: 0.3px;
  text-decoration: none;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.act:active {
  transform: scale(0.94);
  border-color: rgba(255, 60, 70, 0.75);
  background: rgba(214, 22, 31, 0.22);
}

.act svg {
  width: 21px;
  height: 21px;
  fill: var(--red-hot);
}

.act[data-act='save'] svg {
  fill: #fff;
}

/* ───────────────────────────── Controls ─────────────────────────── */

#controls {
  position: fixed;
  top: calc(12px + var(--safe-t));
  right: 12px;
  z-index: 15;
  display: flex;
  gap: 8px;
}

#controls[hidden] {
  display: none;
}

#exit,
#mute,
#flip {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(12, 12, 14, 0.68);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #e6e6ea;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

/* ───────────────────────────── Toast ────────────────────────────── */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(122px + var(--safe-b));
  z-index: 30;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(12, 12, 14, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #eaeaef;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.6px;
  white-space: nowrap;
  transform: translate(-50%, 10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

#toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Landscape phones: shrink the chrome so the card stays visible. */
@media (max-height: 480px) {
  .intro-mark {
    width: 60px;
    height: 60px;
  }
  #intro h1 {
    font-size: 26px;
  }
  .lede {
    margin: 12px auto 16px;
    font-size: 13px;
  }
  #hud {
    padding-top: 8px;
  }
  .hud-id {
    margin-bottom: 8px;
  }
  .act {
    padding: 8px 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro-mark,
  .reticle-beam,
  .reticle .c,
  #start .dot,
  .pulse {
    animation: none;
  }
}
