/* ============================================================
   primae-chars.css — "Meet the pipeline" character cards
   (#pm-chars on primae.html). Six trading-card tiles for the
   stages the live session already names — Turing, Ada, Hopper,
   Knuth, Curie, Hilbert. Front: an abstract mono/geometric
   motif (exactly one accent stroke) + stage number + name +
   role; back (ink ground): the tagline in display type + one
   public-level line. Flip on hover for pointer devices
   (CSS-only); primae-chars.js pins the flip on tap or
   Enter/Space via .pm-chr-on + aria-pressed and adds a
   staggered entrance (root gains .pm-chr-js, grid gains
   .pm-chr-in — without JS the cards simply render visible).
   Scoped under #pm-chars / .pm-chr-*. Reduced motion: instant
   flip, motifs frozen at meaningful frames, no stagger.
   ============================================================ */

/* ---- grid -------------------------------------------------- */
#pm-chars .pm-chr-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-md, 20px);
  list-style: none;
  margin: 0;
  padding: 0;
}

.pm-chr { perspective: 1100px; }

/* ---- the card (a real button: Enter/Space just work) ------- */
.pm-chr-card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 5 / 6;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
@supports not (aspect-ratio: 5 / 6) {
  .pm-chr-card { min-height: 380px; }
}
.pm-chr-card:focus-visible {
  outline: 2px solid var(--accent, #d9542b);
  outline-offset: 4px;
  border-radius: var(--radius-lg, 10px);
}

.pm-chr-flip {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.3, 0.7, 0.2, 1);
}
@media (hover: hover) {
  .pm-chr-card:hover .pm-chr-flip { transform: rotateY(180deg); }
}
.pm-chr-card.pm-chr-on .pm-chr-flip { transform: rotateY(180deg); }

/* ---- faces ------------------------------------------------- */
.pm-chr-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
  border-radius: var(--radius-lg, 10px);
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
/* inner hairline frame — the trading-card border */
.pm-chr-face::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid var(--bb-line, rgba(26, 26, 23, 0.14));
  border-radius: 5px;
  pointer-events: none;
}

.pm-chr-front {
  background: var(--color-surface, #eae7dd);
  border: 1px solid var(--bb-line, rgba(26, 26, 23, 0.14));
}
.pm-chr-back {
  background: var(--color-text, #1a1a17);
  color: var(--color-bg, #f5f4ef);
  border: 1px solid var(--color-text, #1a1a17);
  transform: rotateY(180deg);
}
.pm-chr-back::before { border-color: rgba(245, 244, 239, 0.16); }

/* ---- front content ----------------------------------------- */
.pm-chr-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-family: var(--font-mono, "Geist Mono", ui-monospace, monospace);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--color-muted, #6c6b61);
}
.pm-chr-flipmark { font-size: 12px; letter-spacing: 0; opacity: 0.6; }

.pm-chr-motif {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 0 12px;
}
.pm-chr-motif svg {
  display: block;
  width: min(86%, 225px);
  height: min(100%, 130px);
}

.pm-chr-id {
  border-top: 1px solid var(--bb-line, rgba(26, 26, 23, 0.14));
  padding-top: 13px;
}
.pm-chr-name {
  display: block;
  font-size: clamp(1.2rem, 1.9vw, 1.55rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--color-text, #1a1a17);
}
.pm-chr-role {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono, "Geist Mono", ui-monospace, monospace);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted, #6c6b61);
}

/* ---- back content ------------------------------------------ */
.pm-chr-bhead {
  display: block;
  font-family: var(--font-mono, "Geist Mono", ui-monospace, monospace);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: rgba(245, 244, 239, 0.55);
}
.pm-chr-tag {
  display: block;
  margin: auto 0;
  padding: 12px 0;
  font-size: clamp(1.02rem, 1.55vw, 1.32rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  text-wrap: balance;
  color: var(--color-bg, #f5f4ef);
}
.pm-chr-desc {
  display: block;
  border-top: 1px solid rgba(245, 244, 239, 0.16);
  padding-top: 12px;
  font-size: 0.85rem;
  line-height: 1.55;
  color: rgba(245, 244, 239, 0.72);
}

/* ============================================================
   Motifs — slow, CSS-only; one accent element per card.
   Base styles hold each motif's meaningful final frame, so
   reduced motion can simply switch the animations off.
   ============================================================ */

/* -- Turing · tape: an accent read head steps along the cells - */
.pm-chr-tur-c {
  fill: none;
  stroke: var(--color-muted, #6c6b61);
  stroke-width: 1.2;
  opacity: 0.6;
}
.pm-chr-tur-w { fill: var(--color-muted, #6c6b61); opacity: 0.3; }
.pm-chr-tur-head {
  fill: none;
  stroke: var(--accent, #d9542b);
  stroke-width: 1.5;
  animation: pm-chr-tape 6.5s steps(5, end) infinite alternate;
}
@keyframes pm-chr-tape {
  from { transform: translateX(0); }
  to { transform: translateX(95px); }
}

/* -- Ada · plan tree: the chosen branch draws itself ---------- */
.pm-chr-ada-e {
  fill: none;
  stroke: var(--color-muted, #6c6b61);
  stroke-width: 1.2;
  stroke-linecap: round;
  opacity: 0.55;
}
.pm-chr-ada-n { fill: var(--color-muted, #6c6b61); }
.pm-chr-ada-pick {
  fill: none;
  stroke: var(--accent, #d9542b);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100 100;
  animation: pm-chr-branch 7s ease infinite;
}
@keyframes pm-chr-branch {
  0%, 14% { stroke-dashoffset: 100; opacity: 0; }
  20% { opacity: 1; }
  42% { stroke-dashoffset: 0; opacity: 1; }
  92% { stroke-dashoffset: 0; opacity: 1; }
  98%, 100% { stroke-dashoffset: 0; opacity: 0; }
}
.pm-chr-ada-leaf {
  fill: var(--color-surface, #eae7dd);
  stroke: var(--accent, #d9542b);
  stroke-width: 1.6;
  transform-box: fill-box;
  transform-origin: center;
  animation: pm-chr-leaf 7s ease infinite;
}
@keyframes pm-chr-leaf {
  0%, 36% { transform: scale(0); opacity: 0; }
  44% { transform: scale(1.2); opacity: 1; }
  50% { transform: scale(1); opacity: 1; }
  92% { transform: scale(1); opacity: 1; }
  98%, 100% { transform: scale(1); opacity: 0; }
}

/* -- Hopper · splice: accent lashings bind the two lines ------ */
.pm-chr-hop-r {
  stroke: var(--color-text, #1a1a17);
  stroke-width: 1.5;
  stroke-linecap: round;
  opacity: 0.75;
}
.pm-chr-hop-l {
  stroke: var(--accent, #d9542b);
  stroke-width: 1.4;
  stroke-linecap: round;
  animation: pm-chr-lash 6.5s ease-in-out infinite;
}
.pm-chr-hop-l2 { animation-delay: 0.45s; }
.pm-chr-hop-l3 { animation-delay: 0.9s; }
.pm-chr-hop-l4 { animation-delay: 1.35s; }
@keyframes pm-chr-lash {
  0%, 6% { opacity: 0; }
  16% { opacity: 1; }
  80% { opacity: 1; }
  92%, 100% { opacity: 0; }
}

/* -- Knuth · bracket lattice: a slow accent cursor blink ------ */
.pm-chr-knu-g {
  font: 500 17px var(--font-mono, "Geist Mono", ui-monospace, monospace);
  fill: var(--color-muted, #6c6b61);
  opacity: 0.85;
}
.pm-chr-knu-tie {
  stroke: rgba(26, 26, 23, 0.2);
  stroke-width: 1;
  stroke-dasharray: 1.5 4;
}
.pm-chr-knu-cur {
  fill: var(--accent, #d9542b);
  animation: pm-chr-blink 3s ease-in-out infinite;
}
@keyframes pm-chr-blink {
  0%, 42% { opacity: 1; }
  52%, 86% { opacity: 0.12; }
  100% { opacity: 1; }
}

/* -- Curie · balance: the beam settles, the accent tick lands - */
.pm-chr-cur-st,
.pm-chr-cur-hg,
.pm-chr-cur-pan {
  stroke: var(--color-muted, #6c6b61);
  stroke-width: 1.4;
  stroke-linecap: round;
}
.pm-chr-cur-bm {
  stroke: var(--color-text, #1a1a17);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.pm-chr-cur-piv { fill: var(--color-text, #1a1a17); }
.pm-chr-cur-beam {
  transform-box: view-box;
  transform-origin: 60px 34px;
  animation: pm-chr-weigh 9s ease-in-out infinite;
}
@keyframes pm-chr-weigh {
  0% { transform: rotate(0deg); }
  16% { transform: rotate(-4.5deg); }
  34% { transform: rotate(2deg); }
  50%, 100% { transform: rotate(0deg); }
}
.pm-chr-cur-tick {
  fill: none;
  stroke: var(--accent, #d9542b);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100 100;
  animation: pm-chr-tick 9s ease infinite;
}
@keyframes pm-chr-tick {
  0%, 52% { stroke-dashoffset: 100; opacity: 0; }
  58% { opacity: 1; }
  72% { stroke-dashoffset: 0; opacity: 1; }
  92% { stroke-dashoffset: 0; opacity: 1; }
  98%, 100% { stroke-dashoffset: 0; opacity: 0; }
}

/* -- Hilbert · seal: the tick ring turns, very slowly --------- */
.pm-chr-hil-ring {
  fill: none;
  stroke: var(--color-muted, #6c6b61);
  stroke-width: 1.5;
  stroke-dasharray: 2 5;
  transform-box: view-box;
  transform-origin: 60px 42px;
  animation: pm-chr-spin 46s linear infinite;
}
@keyframes pm-chr-spin {
  to { transform: rotate(360deg); }
}
.pm-chr-hil-in {
  fill: none;
  stroke: var(--color-muted, #6c6b61);
  stroke-width: 1.1;
  opacity: 0.8;
}
.pm-chr-hil-ck {
  fill: none;
  stroke: var(--accent, #d9542b);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- staggered entrance (JS adds .pm-chr-js / .pm-chr-in) --- */
@media (prefers-reduced-motion: no-preference) {
  #pm-chars.pm-chr-js .pm-chr {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.55s ease, transform 0.55s ease;
  }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr {
    opacity: 1;
    transform: none;
  }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr:nth-child(2) { transition-delay: 0.08s; }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr:nth-child(3) { transition-delay: 0.16s; }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr:nth-child(4) { transition-delay: 0.24s; }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr:nth-child(5) { transition-delay: 0.32s; }
  #pm-chars.pm-chr-js .pm-chr-grid.pm-chr-in .pm-chr:nth-child(6) { transition-delay: 0.4s; }
}

/* ---- reduced motion: instant flip, frozen motifs ------------ */
@media (prefers-reduced-motion: reduce) {
  .pm-chr-flip { transition: none; }
  .pm-chr-tur-head,
  .pm-chr-ada-pick, .pm-chr-ada-leaf,
  .pm-chr-hop-l,
  .pm-chr-knu-cur,
  .pm-chr-cur-beam, .pm-chr-cur-tick,
  .pm-chr-hil-ring { animation: none; }
  /* base styles already hold meaningful frames: head parked on
     the first cell, branch + tick fully drawn (dash 100 = full
     path), leaf grown, lashings bound, cursor solid, beam level,
     ring still. */
}

/* ---- responsive -------------------------------------------- */
@media (max-width: 1020px) {
  #pm-chars .pm-chr-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  #pm-chars .pm-chr-grid { gap: 10px; }
  .pm-chr-face { padding: 13px 14px; }
  .pm-chr-face::before { inset: 6px; }
  .pm-chr-motif { padding: 6px 0 8px; }
  .pm-chr-motif svg { width: 90%; height: min(100%, 96px); }
  .pm-chr-meta { font-size: 12px; }
  .pm-chr-id { padding-top: 10px; }
  .pm-chr-name { font-size: 1.08rem; }
  .pm-chr-role { font-size: 12px; letter-spacing: 0.1em; margin-top: 5px; }
  .pm-chr-bhead { font-size: 12px; }
  .pm-chr-tag { font-size: 0.95rem; padding: 10px 0; }
  .pm-chr-desc { font-size: 0.78rem; line-height: 1.5; padding-top: 9px; }
}
