/* ==========================================================================
   Matteo Piotto — hero
   Motion tokens follow the cinematic-gsap-lenis-motion-system skill, except
   where marked "A11Y OVERRIDE" (accessibility wins).
   ========================================================================== */

:root {
  --paper: #f3f1eb;
  --card: #fbfaf6;
  --ink: #0e0f14;
  --blue: #2336e6;
  --metal: #b9bcc4;
  --ink-80: rgb(14 15 20 / .80);
  --ink-65: rgb(14 15 20 / .65); /* MINIMUM for any text (5.6:1 on paper) */
  --rule: rgb(14 15 20 / .14);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --hover: cubic-bezier(.2, 0, 0, 1);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --gutter: clamp(18px, 3.9vw, 56px);
  --chip-a: #e9c97a;
  --chip-b: #c99a3f;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111216;
    --card: #1b1c22;
    --ink: #f1efe8;
    --blue: #8f9bff;
    --ink-80: rgb(241 239 232 / .80);
    --ink-65: rgb(241 239 232 / .65);
    --rule: rgb(241 239 232 / .16);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--paper); /* paper halo keeps the ring ≥3:1 on any backdrop */
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  height: 100svh;
  min-height: 480px;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 0 var(--gutter);
  overflow: clip;
  isolation: isolate;
}
/* paper grain — decorative, ≤ .04 opacity */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 50; pointer-events: none;
  opacity: .04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) { body::after { filter: invert(1); } }

/* Pause-motion toggle (shown only when the WebGL badge runs and motion is allowed) */
.motion-toggle {
  position: absolute; z-index: 4; top: calc(var(--gutter) * .55); right: var(--gutter);
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 0 0 8px;
  border: 0; color: var(--ink); background: var(--paper);
  font: 400 13px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase;
  cursor: pointer;
}
.motion-toggle-icon {
  width: 10px; height: 11px;
  border-inline: 3px solid currentColor;
}
.motion-toggle[aria-pressed="true"] .motion-toggle-icon {
  border: 0; width: 0; height: 0;
  border-left: 10px solid currentColor;
  border-block: 6px solid transparent;
}
.motion-toggle:hover .motion-toggle-label { text-decoration: underline; text-underline-offset: 4px; }

/* Keyboard hint: only while the badge has keyboard focus */
.hint-kbd {
  display: none;
  position: absolute; z-index: 4; left: var(--gutter); top: calc(var(--gutter) * .55);
  min-height: 44px; margin: 0; align-items: center;
  font: 400 13px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink); background: var(--paper);
}
.hero[data-badge-mode="webgl"]:has(#badge-control:focus-visible) .hint-kbd { display: flex; }

/* Giant name — fit to width by hero.js (--name-size); bleeds off the bottom */
.hero-name {
  position: relative; z-index: 2;
  margin: 0 0 -.14em;
  font-weight: 500;
  font-size: var(--name-size, 13.4vw);
  font-variation-settings: "opsz" 144;
  letter-spacing: -0.04em;
  line-height: .8;
  white-space: nowrap;
  transform-origin: 50% 100%;
}
.hero-name-text { display: block; }
.hero-name-probe {
  position: absolute; left: 0; top: 0; visibility: hidden; pointer-events: none;
  font: 500 100px/1 var(--serif); font-variation-settings: "opsz" 144;
  letter-spacing: -0.04em; white-space: nowrap;
}

/* ---------- badge stage ---------- */
.badge-stage {
  position: absolute; inset: 0; z-index: 0;
}
.badge-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block;
  touch-action: pan-y pinch-zoom; /* only touches that start on the card are captured (hero.js) */
  opacity: 0;
  transition: opacity .4s var(--ease);
}
.hero[data-badge-mode="webgl"] .badge-canvas { opacity: 1; }

/* -- the semantic badge -- */
.badge { position: absolute; inset: 0; pointer-events: none; }
.badge-card { position: absolute; pointer-events: auto; }

/* Static / no-JS card (also the forced-colors + no-WebGL fallback) */
.badge:not([data-mode="webgl"]) .badge-card {
  left: 50%; top: 50%;
  width: clamp(260px, 22vw, 340px);
  translate: -50% -50%;
  top: 44%;
}
/* static card + its button sit above the giant name so focus is never obscured (2.4.11) */
.hero:not([data-badge-mode="webgl"]) .badge-stage { z-index: 1; }
.hero:not([data-badge-mode="webgl"]) .hero-name { z-index: 0; }
.badge[data-mode="nojs"] .badge-card { width: min(640px, 50vw); }
.badge[data-mode="nojs"] .badge-flipper { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Hide the static card while WebGL is warming up; failsafe reveal after 3 s */
@media (scripting: enabled) {
  .badge[data-mode="nojs"] .badge-card,
  .badge[data-mode="pending"] .badge-card {
    opacity: 0;
    animation: badge-failsafe 0s linear 3s forwards;
  }
}
@keyframes badge-failsafe { to { opacity: 1; } }

.badge-face {
  container-type: inline-size;
  aspect-ratio: 54 / 86;
  /* % padding resolves against the face's own width (a face can't use its own cqi) */
  padding: 7% 7% 6%;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--rule), 0 24px 48px -24px rgb(14 15 20 / .35);
  /* no overflow:hidden — with long copy or user text-spacing the card grows instead of clipping (1.4.12) */
  position: relative;
  display: flex; flex-direction: column;
}
.bf-row { display: flex; justify-content: space-between; gap: 8px; }
.bf-top { font: 400 max(11px, 4.6cqi)/1.3 var(--mono); letter-spacing: .14em; text-transform: uppercase; }
.bf-name {
  margin: 9cqi 0 0;
  font: 500 19cqi/.86 var(--serif); font-variation-settings: "opsz" 144; letter-spacing: -.03em;
}
.bf-name span { display: block; }
.bf-name .last { color: var(--blue); }
.bf-media { display: flex; justify-content: space-between; align-items: end; margin-top: 5cqi; }
.bf-chip {
  width: 17cqi; height: 13cqi; border-radius: 2.4cqi;
  background:
    linear-gradient(90deg, transparent 32%, rgb(120 80 20 / .35) 32% 34%, transparent 34% 66%, rgb(120 80 20 / .35) 66% 68%, transparent 68%),
    linear-gradient(0deg, transparent 48%, rgb(120 80 20 / .35) 48% 52%, transparent 52%),
    linear-gradient(135deg, var(--chip-a), var(--chip-b));
}
.bf-photo {
  position: relative;
  width: 26cqi; aspect-ratio: 3 / 4; border-radius: 1.6cqi;
  background: color-mix(in srgb, var(--ink) 8%, var(--card));
  display: grid; place-items: center;
}
.bf-mono { font: 500 10cqi/1 var(--serif); color: var(--ink-65); }
.bf-holo {
  position: absolute; right: -4cqi; bottom: -4cqi;
  width: 11cqi; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  font: 500 3.4cqi/1 var(--serif); color: rgb(14 15 20 / .7);
  background: conic-gradient(from 40deg, #d8f1ff, #f7d9ff, #fff3c4, #c9ffe8, #d8f1ff);
}
.bf-dl { margin: 4cqi 0 0; display: grid; gap: 2.6cqi; flex: 1; align-content: start; }
.bf-dl dd { margin: 0; }
.bf-disc dd, .bf-issued, .bf-valid { font: 400 max(11px, 3.6cqi)/1.45 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.bf-disc dd span { display: block; }
.bf-issued, .bf-valid { display: flex; gap: .6em; }
.bf-issued { margin-top: -2cqi; }
.bf-now dt, .bf-prev dt { font: italic 400 max(13px, 4.6cqi)/1.2 var(--serif); }
.bf-now dd { font: 400 max(13px, 4.4cqi)/1.3 var(--serif); }
.bf-tags { display: flex; flex-wrap: wrap; gap: 1.6cqi; margin: 1.2cqi 0 0; padding: 0; list-style: none; }
.bf-tags li {
  padding: 1cqi 2.4cqi; border-radius: 99px;
  background: var(--ink); color: var(--card);
  font: 500 max(11px, 3.2cqi)/1.2 var(--mono); letter-spacing: .06em; text-transform: uppercase;
}
.bf-tags li.is-hl { background: var(--blue); }
@media (prefers-color-scheme: dark) { .bf-tags li.is-hl { color: #0e0f14; } }
.bf-valid { margin-top: auto; padding-right: 26cqi; font-size: max(11px, 3cqi); color: var(--ink-65); }
.bf-barcode {
  position: absolute; right: 7cqi; bottom: 5.5cqi;
  width: 22cqi; height: 5cqi;
  background: repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 3px, var(--ink) 3px 5px, transparent 5px 6px);
  opacity: .7;
}
.badge-front { position: relative; }

.badge-back { gap: 5cqi; }
.bb-heading { margin: 0; font: 500 13cqi/.95 var(--serif); font-variation-settings: "opsz" 144; color: var(--blue); }
.bb-bio { margin: 0; font: 400 max(14px, 5.6cqi)/1.35 var(--serif); }
.bb-links { margin: auto 0 0; padding: 0; list-style: none; display: grid; gap: 1cqi; }
.badge-link {
  display: inline-flex; align-items: center; min-height: 24px;
  font: 400 max(12px, 4cqi)/1.3 var(--mono); letter-spacing: .08em;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
}

/* Static mode: CSS 3D flip */
.badge[data-mode="static"] .badge-flipper {
  display: grid;
  transform-style: preserve-3d;
  transition: transform .9s var(--ease);
}
.badge[data-mode="static"] .badge-face { grid-area: 1 / 1; backface-visibility: hidden; }
.badge[data-mode="static"] .badge-back { transform: rotateY(180deg); }
.badge[data-mode="static"].is-flipped .badge-flipper { transform: rotateY(180deg); }
/* the outgoing face keeps rendering until the card is edge-on, then leaves the a11y tree */
.badge[data-mode="static"] .badge-face[hidden] {
  display: flex; visibility: hidden;
  transition: visibility 0s linear .45s;
}
.badge[data-mode="static"] .badge-card { perspective: 1400px; cursor: pointer; }
.badge[data-mode="static"] .badge-control {
  position: absolute; left: 50%; top: calc(100% + 20px); translate: -50% 0;
  min-height: 44px; padding: 0 20px;
  border: 1px solid var(--ink); border-radius: 99px;
  background: var(--paper); color: var(--ink);
  font: 400 13px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase;
  cursor: pointer; white-space: nowrap;
}

/* WebGL mode: faces become an invisible-but-real overlay matching the projected card.
   Text stays in the accessibility tree (opacity, not display/visibility). */
.badge[data-mode="webgl"] .badge-card {
  left: 0; top: 0;
  pointer-events: none; /* pointer goes to the canvas; keyboard/AT use the button */
}
.badge[data-mode="webgl"] .badge-flipper { position: absolute; inset: 0; }
.badge[data-mode="webgl"] .badge-face {
  position: absolute; inset: 0; aspect-ratio: auto;
  background: none; box-shadow: none;
  overflow: hidden;
}
.badge[data-mode="webgl"] .badge-face > *:not(.bb-links),
.badge[data-mode="webgl"] .bb-links li > * { opacity: 0; }
.badge[data-mode="webgl"] .badge-link:focus-visible {
  opacity: 1;
  position: relative; z-index: 3;
  padding: 6px 10px; border-radius: 6px;
  background: var(--card); color: var(--ink);
  font-size: 13px;
}
.badge[data-mode="webgl"] .badge-control {
  position: absolute; inset: 0;
  background: transparent; border: 0; padding: 0;
  border-radius: 10px;
  color: transparent;
}
.badge[data-mode="webgl"] .badge-control-text { position: absolute; opacity: 0; }
.badge[data-mode="webgl"] .badge-control:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--paper), inset 0 0 0 2px var(--paper);
}

/* ---------- load reveal (pure CSS) ----------
   A11Y OVERRIDE of the skill: the skill hides reveal targets with
   `visibility:hidden` until GSAP runs. That removes text from the
   accessibility tree and hides content if a CDN import fails, so the
   reveal here is CSS-only, uses opacity/transform only, and is wrapped in
   prefers-reduced-motion: no-preference (switches live, no JS needed). */
@media (prefers-reduced-motion: no-preference) {
  [data-reveal] {
    animation: reveal-up .55s var(--ease) both;
    animation-delay: calc(.12s + var(--i, 0) * .06s); /* last item ends ≤ .8 s */
  }
  .hero-name {
    animation: wipe-up 1s var(--ease) .05s both;
  }
}
@keyframes reveal-up { from { opacity: 0; transform: translateY(12px); } }
@keyframes wipe-up { from { clip-path: inset(100% -10% 0 -10%); } to { clip-path: inset(-10% -10% 0 -10%); } }

@media (prefers-reduced-motion: reduce) {
  .badge[data-mode="static"] .badge-flipper { transition: none; }
  .badge[data-mode="static"].is-flipped .badge-flipper { transform: none; }
  .badge[data-mode="static"] .badge-back { transform: none; }
  .badge[data-mode="static"] .badge-face { transition: opacity .15s linear; }
  .badge[data-mode="static"] .badge-face[hidden] { opacity: 0; transition: opacity .15s linear, visibility 0s linear .15s; }
  .badge-canvas { transition: none; }
}

/* ---------- forced colours: hide the canvas, show the HTML badge ---------- */
@media (forced-colors: active) {
  .badge-canvas { display: none; }
  .badge-face { border: 1px solid CanvasText; box-shadow: none; }
  .bf-tags li, .bf-tags li.is-hl { border: 1px solid CanvasText; background: Canvas; color: CanvasText; }
  .bf-chip, .bf-holo, .bf-barcode { forced-color-adjust: none; }
  body::after { display: none; }
}

/* ---------- small screens ---------- */
@media (max-width: 759px) {
  .badge:not([data-mode="webgl"]) .badge-card { width: min(280px, 72vw); top: 44%; }
  .badge[data-mode="nojs"] .badge-card { width: min(520px, 92vw); }
}
/* short or zoomed viewports: let the page grow and scroll instead of clipping the static card */
@media (max-height: 560px) {
  .hero:not([data-badge-mode="webgl"]) { height: auto; min-height: 100svh; padding-top: 24px; gap: 32px; }
  .hero:not([data-badge-mode="webgl"]) .badge-stage { position: relative; inset: auto; }
  .hero:not([data-badge-mode="webgl"]) .badge-card { position: relative; left: auto; top: auto; translate: none; margin: 56px auto 80px; }
}
