/* ==========================================================================
   Result card
   A 9:16 terminal printout, story-shaped so the download (next step) drops
   straight into Instagram stories. Everything is sized in container units
   (cqw), so the card scales as one piece and exports identically.
   ========================================================================== */

.card-wrap {
  container-type: inline-size;
  width: min(100%, 380px);
  margin: 1.2rem 0 0;
}

.card {
  --pad: 5.5cqw;
  position: relative;
  aspect-ratio: 9 / 16;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 3.6cqw;
  line-height: 1.5;
  color: var(--ph);
  text-shadow: none;           /* don't inherit the terminal line glow */
  white-space: normal;
  background:
    radial-gradient(120% 70% at 50% 30%, #12160d 0%, #080907 75%);
  border: 1px solid rgba(234, 255, 165, 0.22);
  border-radius: 3cqw;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 40px rgba(234, 255, 165, 0.07),
    0 30px 80px rgba(0, 0, 0, 0.55);
}

/* the card carries its own scanlines, so they survive the export */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0, 0, 0, 0.18) 3px
  );
}

.card .glow { text-shadow: 0 0 1.6cqw var(--ph-glow), 0 0 5cqw var(--ph-bloom); }
.card .dim  { color: var(--ph-dim); }
.card .faint { color: var(--ph-faint); }

/* title bar */
.card__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3cqw var(--pad);
  border-bottom: 1px solid rgba(234, 255, 165, 0.12);
  font-size: 2.9cqw;
  letter-spacing: 0.08em;
  color: var(--ph-dim);
}

/* Compound logo: as tall as the header text line, lime, no filters so the
   export stays crisp */
.card__logo {
  display: block;
  height: 1.2em;
  width: auto;
}

.card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 3.4cqw var(--pad) 0;
  min-height: 0;
}

.card__line { margin: 0; }
.card__line .k { color: var(--ph-dim); }

/* viewport: the character, framed like a monitor feed */
.card__view {
  position: relative;
  flex: none;
  height: 73cqw;               /* fixed, so every card frames the same */
  margin: 3cqw 0 3.8cqw;
  border: 1px solid rgba(234, 255, 165, 0.16);
  border-radius: 1.4cqw;
  overflow: hidden;
  background:
    linear-gradient(rgba(234, 255, 165, 0.05) 1px, transparent 1px) 0 0 / 100% 6cqw,
    linear-gradient(90deg, rgba(234, 255, 165, 0.05) 1px, transparent 1px) 0 0 / 6cqw 100%,
    radial-gradient(80% 70% at 50% 60%, rgba(234, 255, 165, 0.09), transparent 70%),
    #070806;
}

.card__img {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
}
.card__img[data-fit="fill"]   { background-size: cover; }
.card__img[data-fit="cutout"] {
  inset: 4cqw 3cqw 0;
  background-size: contain;
  background-position: 50% 100% !important;
}

/* a soft phosphor fade at the bottom of the feed + corner brackets */
.card__view::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 70%, rgba(7, 8, 6, 0.75));
  pointer-events: none;
}

.card__corner {
  position: absolute;
  z-index: 1;
  width: 4cqw;
  height: 4cqw;
  border: 0 solid var(--ph);
  opacity: 0.7;
}
.card__corner--tl { top: 2cqw; left: 2cqw; border-top-width: 1.5px; border-left-width: 1.5px; }
.card__corner--tr { top: 2cqw; right: 2cqw; border-top-width: 1.5px; border-right-width: 1.5px; }
.card__corner--bl { bottom: 2cqw; left: 2cqw; border-bottom-width: 1.5px; border-left-width: 1.5px; }
.card__corner--br { bottom: 2cqw; right: 2cqw; border-bottom-width: 1.5px; border-right-width: 1.5px; }

.card__tag {
  position: absolute;
  z-index: 1;
  left: 7.5cqw;                /* clear of the corner bracket */
  bottom: 2.2cqw;
  font-size: 2.6cqw;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ph);
  text-shadow: 0 0 1.6cqw rgba(0, 0, 0, 0.9);
}

/* result */
.card__name {
  margin: 0.8cqw 0 3.4cqw;
  font-size: 8.6cqw;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}


/* power readout: four mini meters */
.card__readout {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2.4cqw;
  margin: auto 0 0;            /* sits on the footer whatever the copy length */
  padding-top: 3.6cqw;
  border-top: 1px dashed rgba(234, 255, 165, 0.14);
  font-size: 2.4cqw;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.card__meter { display: flex; flex-direction: column; gap: 1.2cqw; }
.card__meter.is-top { color: var(--ph); }
.card__meter:not(.is-top) { color: var(--ph-dim); }
.card__cells { display: flex; gap: 0.7cqw; }
.card__cells i {
  flex: 1;
  height: 1.6cqw;
  background: rgba(234, 255, 165, 0.12);
}
.card__cells i.on {
  background: var(--ph);
  box-shadow: 0 0 1.4cqw var(--ph-glow);
}

.card__foot {
  padding: 4cqw var(--pad) 4.6cqw;
  color: var(--ph-faint);
}
.card__foot-row {
  display: flex;
  justify-content: space-between;
  font-size: 2.6cqw;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
/* handle + quiz link: lowercase, untracked, so the whole line fits */
/* the costume protocol is its own statement, not a continuation of the trait */
.card__line--gap { margin: 2.6cqw 0 2.2cqw; }  /* bottom: a minimum gap above the readout, even for 3-line costumes */

/* the address is the one thing on the footer meant to be acted on */
.card__foot-link .url {
  color: var(--ph);
  text-shadow: 0 0 1.4cqw var(--ph-glow);
}

.card__foot-link {
  margin: 2.4cqw 0 0;
  color: var(--ph-dim);             /* muted but readable; the URL is the highlight */
  font-size: 2.2cqw;                /* 63 characters inside the 89cqw text width */
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Reveal: the card powers on, the feed scans in top to bottom, lines follow
   -------------------------------------------------------------------------- */

.card.is-revealing {
  animation: card-on 520ms var(--ease-out) both;
}
.card.is-revealing .card__img {
  animation: feed-scan 1100ms 260ms steps(22) both;
}
.card.is-revealing .card__view::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--ph);
  box-shadow: 0 0 12px var(--ph-glow), 0 0 30px var(--ph-glow);
  animation: scan-line 1100ms 260ms linear both;
}
.card.is-revealing .reveal {
  animation: cmd-in 320ms var(--ease-out) both;
  animation-delay: calc(1250ms + var(--i, 0) * 90ms);
}

@keyframes card-on {
  from { opacity: 0; transform: scale(0.97); filter: brightness(2.5); }
  to   { opacity: 1; transform: none; filter: none; }
}
@keyframes feed-scan {
  from { clip-path: inset(0 0 100% 0); }
  to   { clip-path: inset(0 0 0 0); }
}
@keyframes scan-line {
  0%   { top: 0; opacity: 1; }
  96%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .card.is-revealing,
  .card.is-revealing .card__img,
  .card.is-revealing .reveal { animation: none; }
  .card.is-revealing .card__view::before { display: none; }
}

/* --------------------------------------------------------------------------
   Processing screen: live meters + dose bar (terminal lines, not the card)
   -------------------------------------------------------------------------- */

.meter-row {
  display: grid;
  grid-template-columns: 11ch max-content 3ch;
  justify-content: start;
  gap: 1ch;
}
.meter-row .cells { letter-spacing: 0.08em; }
.meter-row .val { text-align: right; }

/* --------------------------------------------------------------------------
   Result actions: a command bar that sticks to the bottom of the screen
   while the card is taller than the phone, and sits under it otherwise.
   -------------------------------------------------------------------------- */

.result-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  width: min(100%, 380px);
  margin-top: 0.8rem;
  padding: 0.6rem 0 calc(0.8rem + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(7, 8, 6, 0), var(--bg) 30%);
}

.result-actions__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
  margin-left: -0.6ch;
}

/* commands stay whole: "[ save ]" never splits across lines */
.result-actions__row .cmd {
  flex: none;
  white-space: nowrap;
  opacity: 1;
  animation: none;
}

/* tickets always gets its own full-width row under [ save ] [ share ] */
.result-actions__row .cmd--primary {
  flex: 0 0 calc(100% - 0.6ch);  /* the row is pulled 0.6ch left for the brackets */
  justify-content: center;
  margin: 0.3rem 0 0 0.6ch;
}

/* the one filled command: tickets */
.cmd--primary {
  display: inline-flex;
  align-items: center;
  padding: 0 1.2ch;
  background: var(--ph);
  color: var(--bg);
  text-decoration: none;
  text-shadow: none;
  font-weight: 700;
  box-shadow: 0 0 18px var(--ph-glow);
  animation: cta-pulse 2.4s ease-in-out infinite;
}
.cmd--primary:focus-visible { outline: 1px solid var(--ph); outline-offset: 3px; }
@media (hover: hover) {
  .cmd--primary:hover { box-shadow: 0 0 30px var(--ph-glow), 0 0 60px var(--ph-bloom); }
}
@keyframes cta-pulse {
  0%, 100% { box-shadow: 0 0 14px var(--ph-glow); }
  50%      { box-shadow: 0 0 28px var(--ph-glow), 0 0 50px var(--ph-bloom); }
}

.result-actions__status {
  min-height: 1.4em;
  margin: 0 0 0.2rem;
  font-size: 0.8em;
  color: var(--ph-dim);
  opacity: 0;
  transition: opacity 200ms ease;
}
.result-actions__status.is-on { opacity: 1; }

.retake {
  margin-top: 0.4rem;
  font-size: 0.8em;
}
.retake .cmd { min-height: 36px; color: var(--ph-dim); text-shadow: none; }

/* export source: pinned to the viewport's top-left (html2canvas needs real
   on-screen coordinates) inside a zero-size clip, so it's never seen */
.export-stage {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.result-actions__debug {
  margin-top: 0.4rem;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--ph-dim);
}

/* in-app browser fallback: hold to save */
.save-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: var(--gutter);
  background: var(--bg);
}
.save-overlay__img {
  max-height: 72dvh;
  max-width: 100%;
  border-radius: 10px;
  box-shadow: 0 0 40px rgba(234, 255, 165, 0.12);
  -webkit-touch-callout: default;
}
.save-overlay__note {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ph-dim);
}

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