/* =========================================================
   ALIEN SCANNER — Phase 1 styles
   Detector / xeno-tech aesthetic: dark base, acid-green HUD.
   ========================================================= */

:root {
  --bg:        #04070c;
  --bg-2:      #0a1018;
  --acid:      #6bff9e;   /* primary detector green */
  --acid-dim:  #2f7d54;
  --cyan:      #57e8ff;
  --danger:    #ff5470;
  --ink:       #dff7e8;
  --muted:     #6f8a7d;
  --hud-glow:  0 0 8px rgba(107, 255, 158, .55);
  --font: "SF Mono", "Segoe UI Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The [hidden] attribute must always beat an author `display` rule,
   or overlays with display:grid/flex never actually hide. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Full-bleed screens; only the active one shows. */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  /* respect iPhone notch / home indicator */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.is-active { display: flex; }

/* ============================ START SCREEN ============================ */

#screen-start {
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(120% 90% at 50% 8%, #0d2a1e 0%, var(--bg-2) 42%, var(--bg) 100%);
  overflow: hidden;
}

/* drifting starfield */
.stars {
  position: absolute;
  inset: -50%;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #9affc4 40%, transparent),
    radial-gradient(1px 1px at 70% 60%, #7de8ff 40%, transparent),
    radial-gradient(1px 1px at 40% 80%, #ffffff 40%, transparent),
    radial-gradient(1.5px 1.5px at 85% 20%, #9affc4 40%, transparent),
    radial-gradient(1px 1px at 55% 15%, #ffffff 40%, transparent),
    radial-gradient(1px 1px at 10% 65%, #7de8ff 40%, transparent);
  background-size: 400px 400px;
  opacity: .5;
  animation: drift 60s linear infinite;
}
@keyframes drift { to { transform: translateY(-120px); } }

.start-inner {
  position: relative;
  z-index: 1;
  padding: 24px;
  max-width: 520px;
}

.badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: .28em;
  color: var(--acid);
  border: 1px solid var(--acid-dim);
  border-radius: 999px;
  padding: 7px 16px;
  margin-bottom: 28px;
  text-shadow: var(--hud-glow);
  animation: flicker 6s infinite;
}

.title {
  font-size: clamp(48px, 16vw, 96px);
  line-height: .92;
  font-weight: 800;
  letter-spacing: .04em;
  color: #fff;
  text-shadow: 0 0 18px rgba(107,255,158,.35);
}
.title span {
  display: block;
  color: var(--acid);
  text-shadow: var(--hud-glow), 0 0 26px rgba(107,255,158,.5);
}

.tagline {
  margin: 22px auto 40px;
  max-width: 340px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: .02em;
}

/* Big glowing START button */
.btn-start {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 176px;
  height: 176px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: radial-gradient(circle at 50% 40%, #0f3a28 0%, #071a12 70%);
  box-shadow:
    0 0 0 1px var(--acid-dim) inset,
    0 0 40px rgba(107,255,158,.25),
    0 0 90px rgba(107,255,158,.12);
  transition: transform .12s ease, box-shadow .2s ease;
}
.btn-start__label {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--acid);
  text-shadow: var(--hud-glow);
  z-index: 1;
}
.btn-start__ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid var(--acid);
  opacity: .6;
  animation: pulse-ring 2.4s ease-out infinite;
}
.btn-start:hover { box-shadow: 0 0 0 1px var(--acid) inset, 0 0 60px rgba(107,255,158,.4); }
.btn-start:active { transform: scale(.95); }

.disclaimer {
  margin-top: 40px;
  color: #3f5a4d;
  font-size: 11px;
  letter-spacing: .08em;
}

@keyframes pulse-ring {
  0%   { transform: scale(1);    opacity: .6; }
  100% { transform: scale(1.35); opacity: 0;  }
}
@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97%, 99%      { opacity: .35; }
}

/* ============================ CAMERA SCREEN ============================ */

#screen-camera {
  background: #000;
}

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}

.viewport__video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* mirror like a selfie / bathroom mirror */
  transform: scaleX(-1);
  background: #05080d;
}

/* -------- HUD overlay -------- */
.hud { position: absolute; inset: 0; pointer-events: none; }

.hud__vignette {
  position: absolute; inset: 0;
  background: radial-gradient(120% 100% at 50% 50%,
              transparent 55%, rgba(0,0,0,.55) 100%);
  mix-blend-mode: multiply;
}

/* travelling scan line */
.hud__scanline {
  position: absolute;
  left: 0; right: 0; height: 140px;
  background: linear-gradient(to bottom,
              transparent, rgba(107,255,158,.10) 45%,
              rgba(107,255,158,.22) 50%, transparent);
  box-shadow: 0 0 20px rgba(107,255,158,.25);
  animation: scan 3.4s cubic-bezier(.6,0,.4,1) infinite;
}
@keyframes scan {
  0%   { top: -140px; }
  100% { top: 100%; }
}

/* corner brackets */
.corner {
  position: absolute;
  width: 34px; height: 34px;
  border: 2px solid var(--acid);
  filter: drop-shadow(var(--hud-glow));
  opacity: .9;
}
.corner--tl { top: 20px;  left: 20px;  border-right: none; border-bottom: none; }
.corner--tr { top: 20px;  right: 20px; border-left: none;  border-bottom: none; }
.corner--bl { bottom: 20px; left: 20px;  border-right: none; border-top: none; }
.corner--br { bottom: 20px; right: 20px; border-left: none;  border-top: none; }

/* center reticle */
.reticle {
  position: absolute;
  top: 50%; left: 50%;
  width: min(58vw, 260px); height: min(58vw, 260px);
  transform: translate(-50%, -50%);
}
.reticle__ring {
  position: absolute; inset: 0;
  border: 1px dashed rgba(107,255,158,.5);
  border-radius: 50%;
  animation: spin 14s linear infinite;
}
.reticle__cross {
  position: absolute; background: rgba(107,255,158,.5);
}
.reticle__cross--h { top: 50%; left: 42%; right: 42%; height: 1px; }
.reticle__cross--v { left: 50%; top: 42%; bottom: 42%; width: 1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* top + bottom HUD text rows */
.hud__top, .hud__bottom {
  position: absolute; left: 0; right: 0;
  display: flex; justify-content: space-between;
  padding: 30px 34px;
  font-size: 12px; letter-spacing: .18em;
  color: var(--acid); text-shadow: var(--hud-glow);
}
.hud__top { top: 0; }
.hud__bottom { bottom: 0; justify-content: center; }
.hud__tag--right { color: var(--danger); text-shadow: 0 0 8px rgba(255,84,112,.6); }
.hud__readout { opacity: .85; animation: flicker 5s infinite; }

.rec-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 8px var(--danger);
  animation: blink 1.2s steps(1) infinite;
}
@keyframes blink { 50% { opacity: .2; } }

/* -------- camera error / permission message -------- */
.cam-message {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  text-align: center; padding: 32px;
  background: rgba(4,7,12,.92);
  z-index: 5;
}
.cam-message p { color: var(--ink); max-width: 320px; line-height: 1.5; font-size: 14px; }

/* -------- control bar -------- */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px calc(22px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, #04070c 40%, transparent);
}
.controls__spacer, .btn-ghost--icon { width: 52px; }

.shutter {
  position: relative;
  width: 84px; height: 84px;
  border: none; background: none; cursor: pointer;
  display: grid; place-items: center;
}
.shutter__ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 3px solid var(--acid);
  box-shadow: var(--hud-glow), inset 0 0 12px rgba(107,255,158,.25);
}
.shutter__core {
  width: 62px; height: 62px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #b9ffd4, var(--acid));
  box-shadow: 0 0 18px rgba(107,255,158,.6);
  transition: transform .1s ease;
}
.shutter:active .shutter__core { transform: scale(.86); }

.btn-ghost {
  font-family: var(--font);
  background: rgba(107,255,158,.06);
  border: 1px solid var(--acid-dim);
  color: var(--acid);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px; letter-spacing: .1em;
  cursor: pointer;
  transition: background .15s ease;
}
.btn-ghost:hover { background: rgba(107,255,158,.14); }
.btn-ghost--icon {
  height: 52px; display: grid; place-items: center;
  font-size: 26px; line-height: 1; padding: 0;
}

/* frozen still sits above the live video, below the HUD */
.viewport__freeze {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}
.hud { z-index: 2; }

/* ============================ SCAN THEATER (Phase 2) ============================ */

.scan {
  position: absolute; inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

/* sweeping perspective grid */
.scan__grid {
  position: absolute; inset: -20% -20% -20% -20%;
  background-image:
    linear-gradient(rgba(107,255,158,.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(107,255,158,.35) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(120% 90% at 50% 50%, #000 30%, transparent 78%);
  -webkit-mask-image: radial-gradient(120% 90% at 50% 50%, #000 30%, transparent 78%);
  opacity: .0;
  animation: grid-in .5s ease forwards, grid-pan 6s linear infinite;
}
@keyframes grid-in { to { opacity: .55; } }
@keyframes grid-pan { to { background-position: 0 42px, 42px 0; } }

/* bright horizontal scanning beam */
.scan__beam {
  position: absolute; left: -10%; right: -10%; height: 3px;
  background: linear-gradient(90deg, transparent, var(--acid), #fff, var(--acid), transparent);
  box-shadow: 0 0 24px 6px rgba(107,255,158,.7);
  animation: beam 1.5s ease-in-out infinite;
}
@keyframes beam {
  0%   { top: 8%;  opacity: .3; }
  50%  { top: 92%; opacity: 1;  }
  100% { top: 8%;  opacity: .3; }
}

/* white capture flash on freeze */
.scan__flash {
  position: absolute; inset: 0; background: #eafff2; opacity: 0;
}
.scan.is-freezing .scan__flash { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

/* target lock brackets that snap inward */
.scan__lock {
  position: absolute; top: 50%; left: 50%;
  width: min(64vw, 300px); height: min(64vw, 300px);
  transform: translate(-50%, -50%);
  animation: lock-in .6s cubic-bezier(.2,.9,.2,1) forwards;
}
@keyframes lock-in {
  0%   { width: min(92vw, 460px); height: min(92vw, 460px); opacity: 0; }
  100% { opacity: 1; }
}
.scan__lock-c {
  position: absolute; width: 30px; height: 30px;
  border: 3px solid var(--cyan);
  filter: drop-shadow(0 0 8px rgba(87,232,255,.7));
}
.scan__lock-c--tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.scan__lock-c--tr { top: 0; right: 0; border-left: none;  border-bottom: none; }
.scan__lock-c--bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.scan__lock-c--br { bottom: 0; right: 0; border-left: none;  border-top: none; }

/* rolling terminal readout */
.scan__log {
  position: absolute;
  left: 22px; top: 84px;
  list-style: none;
  font-size: 12px; line-height: 1.7;
  letter-spacing: .06em;
  color: var(--acid);
  text-shadow: var(--hud-glow);
  max-width: 74%;
}
.scan__log li {
  opacity: 0;
  animation: log-in .3s ease forwards;
  white-space: nowrap;
  overflow: hidden;
}
.scan__log li::before { content: "› "; color: var(--cyan); }
.scan__log li b { color: #fff; font-weight: 600; }
@keyframes log-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: .95; transform: none; }
}

/* percentage + progress meter, bottom center */
.scan__meter {
  position: absolute;
  left: 0; right: 0; bottom: 30px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 0 28px;
}
.scan__pct {
  font-size: clamp(56px, 20vw, 108px);
  font-weight: 800; line-height: 1;
  color: #fff;
  text-shadow: 0 0 22px rgba(107,255,158,.6);
  font-variant-numeric: tabular-nums;
}
.scan__pct i { font-size: .4em; color: var(--acid); font-style: normal; margin-left: 4px; }
.scan__bar {
  width: min(78vw, 420px); height: 6px;
  background: rgba(107,255,158,.14);
  border: 1px solid var(--acid-dim);
  border-radius: 999px; overflow: hidden;
}
.scan__bar span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--acid-dim), var(--acid), #fff);
  box-shadow: var(--hud-glow);
}
.scan__label {
  font-size: 13px; letter-spacing: .2em; color: var(--acid);
  text-shadow: var(--hud-glow); text-transform: uppercase;
}

/* ============================ VERDICT MEME CARD (Phase 3) ============================ */
.reveal {
  position: absolute; inset: 0; z-index: 4;
  display: grid; place-content: safe center; justify-items: center; gap: 18px;
  padding: 20px;
  background: radial-gradient(120% 90% at 50% 40%, rgba(6,26,18,.9), rgba(4,7,12,.97));
  overflow: auto;
}

/* the card itself — designed to be screenshot / shared */
.card {
  --card-accent: var(--acid);
  width: min(92vw, 360px);
  background: linear-gradient(180deg, #0b1219, #060a0f);
  border: 1px solid var(--card-accent);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), 0 24px 60px rgba(0,0,0,.6),
              0 0 42px color-mix(in srgb, var(--card-accent) 35%, transparent);
  animation: card-in .5s cubic-bezier(.2,.9,.2,1);
}
@keyframes card-in {
  0%   { transform: scale(.8) translateY(20px); opacity: 0; }
  100% { transform: none; opacity: 1; }
}

.card__frame { position: relative; aspect-ratio: 4 / 5; overflow: hidden; }
.card__photo { width: 100%; height: 100%; object-fit: cover; display: block; }

.card__scanlines {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.16) 2px 3px);
  mix-blend-mode: multiply;
}

/* verdict banner across the top */
.card__badge {
  position: absolute; top: 14px; left: 14px;
  font-size: 13px; font-weight: 800; letter-spacing: .14em;
  padding: 7px 12px; border-radius: 8px;
  color: #04120b; background: var(--card-accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--card-accent) 60%, transparent);
}
.card__badge.is-human { color: #fff; }

/* big match % bottom-right of the photo */
.card__match {
  position: absolute; right: 14px; bottom: 12px; text-align: right;
  text-shadow: 0 2px 10px rgba(0,0,0,.7);
}
.card__match-num {
  display: block; font-size: 46px; font-weight: 800; line-height: .9;
  color: #fff; font-variant-numeric: tabular-nums;
}
.card__match-lbl {
  display: block; font-size: 11px; letter-spacing: .22em;
  color: var(--card-accent);
}

.card__body { padding: 16px 18px 8px; }
.card__species {
  font-size: 22px; font-weight: 800; letter-spacing: .02em;
  color: #fff; line-height: 1.1; margin-bottom: 10px;
}
.card__meta {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 10.5px; letter-spacing: .1em; color: var(--muted);
  margin-bottom: 12px; flex-wrap: wrap;
}
.card__meta b { color: var(--card-accent); font-weight: 700; }

.card__traits { list-style: none; display: grid; gap: 6px; }
.card__traits li {
  font-size: 12.5px; color: var(--ink); line-height: 1.35;
  padding-left: 16px; position: relative;
}
.card__traits li::before {
  content: "▸"; position: absolute; left: 0; color: var(--card-accent);
}

.card__foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px 16px; margin-top: 6px;
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: 11px; letter-spacing: .1em;
}
.card__brand { color: #fff; font-weight: 700; }
.card__url { color: var(--card-accent); }

.card__actions {
  display: flex; gap: 12px;
  flex-wrap: wrap; justify-content: center;
}

/* filled primary button (SHARE) */
.btn-solid {
  font-family: var(--font);
  background: linear-gradient(180deg, #b9ffd4, var(--acid));
  color: #04120b;
  border: none;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14px; font-weight: 700; letter-spacing: .1em;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(107,255,158,.5);
  transition: transform .12s ease, box-shadow .2s ease;
}
.btn-solid:hover  { box-shadow: 0 0 26px rgba(107,255,158,.7); }
.btn-solid:active { transform: scale(.96); }

/* transient toast (save confirmation / errors) */
.toast {
  position: absolute;
  left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 6;
  background: rgba(4,7,12,.94);
  border: 1px solid var(--acid-dim);
  color: var(--ink);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px; letter-spacing: .04em;
  box-shadow: var(--hud-glow);
  max-width: 80%; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .hud__scanline, .reticle__ring, .btn-start__ring, .stars,
  .rec-dot, .hud__readout, .badge,
  .scan__beam, .scan__grid, .scan__lock, .scan__flash { animation: none; }
}

/* =========================================================
   THE CODEX (collection + score)
   ========================================================= */
.btn-codex {
  margin-top: 18px;
  letter-spacing: .12em;
}
.btn-codex b {
  color: var(--acid);
  font-weight: 700;
  margin-left: 6px;
}
.btn-ghost--sm {
  font-size: 11px;
  padding: 6px 12px;
  opacity: .6;
}

.codex {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 22px 18px 40px;
  /* the screen is a fixed flex column; these two let a long Codex scroll
     inside it instead of overflowing off the bottom of the phone */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.codex__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.codex__title {
  font-size: 15px;
  letter-spacing: .22em;
  color: var(--acid);
  text-shadow: var(--hud-glow);
}

.codex__stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stat {
  border: 1px solid rgba(107,255,158,.18);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
  background: rgba(107,255,158,.04);
}
.stat b {
  display: block;
  font-size: 18px;
  color: var(--acid);
  text-shadow: var(--hud-glow);
}
.stat span {
  font-size: 9px;
  letter-spacing: .14em;
  color: var(--muted);
}

.codex__grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.codex__cell {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  padding: 10px 11px;
  background: rgba(255,255,255,.02);
  opacity: .45;                       /* undiscovered: dimmed */
}
.codex__cell.is-found {
  opacity: 1;
  border-color: var(--r);
  background: color-mix(in srgb, var(--r) 8%, transparent);
}
.codex__name {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.3;
}
.codex__name--hidden { color: var(--muted); letter-spacing: .1em; }
.codex__planet {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}
.codex__tag {
  display: inline-block;
  margin-top: 7px;
  font-size: 9px;
  letter-spacing: .1em;
  color: var(--r);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 7px;
}
.codex__count {
  font-size: 9px;
  color: var(--muted);
  margin-top: 5px;
}
.codex__hint {
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  margin: 22px 0 14px;
}
.codex__hint b { color: var(--ink); }

/* ---- card: rarity + score ---- */
.card__namerow {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.card__rarity {
  font-size: 9px;
  letter-spacing: .14em;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.card__score {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}
.card__new {
  font-size: 9px;
  letter-spacing: .14em;
  color: #04070c;
  background: var(--acid);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 700;
  animation: newPulse 1.1s ease-in-out infinite;
}
.card__pts {
  font-size: 12px;
  font-weight: 700;
  color: var(--acid);
  letter-spacing: .08em;
}
.card__pts.is-dim {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .12em;
}
@keyframes newPulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(107,255,158,.5); }
  50%      { transform: scale(1.06); box-shadow: 0 0 0 5px rgba(107,255,158,0); }
}
@media (prefers-reduced-motion: reduce) {
  .card__new { animation: none; }
}
