/* Schematic of the Access Granted installation (src/pages/work/access-granted.md). There is no script.
   The eyebrow, title and note use the site's .echo-eyebrow, .echo-title and .echo-note.

   Geometry: the plan is 100 units wide, and one unit is 1cqw of the plan. Every part is placed from the numbers
   set on .badge-plan, once for the phone (the screen above, then the computer, the readers and the cards) and
   once for wide screens (the screen on the left, the rest on the right). The cards in the deck and the card on a
   reader are the same size, and so are the three readers.

   Animation: one loop of 21 seconds in six slots of 3.5 seconds. In each slot a card leaves the deck for a reader,
   the signal runs to the server, which logs the read, then to the computer and on to the screen, and the picture
   changes: reader 1 changes its shape,
   reader 2 its colour, reader 3 its movement. Only opacity and transform are animated. With reduced motion
   nothing moves: one card lies on reader 1 and its path to the screen is lit. */

.badge {
  --badge-wall: var(--schematic-wall);
  --badge-line: var(--schematic-line);
  --badge-lit: #fff;
  margin: clamp(0.6rem, 1.6vw, 1.2rem) 0 clamp(2rem, 4vw, 3.2rem);
}

.badge-plan {
  /* Height of the plan, then: the screen (centre and diameter), the computer and the server (left, top, width,
     height), the readers (three centres, width, height, width of a caption), the line that joins them, the deck (left, top,
     step between two cards), a card (width, height), and the cable from the computer to the screen. */
  --h: 171;
  --sx: 50; --sy: 42; --sd: 66;
  --px: 22; --py: 81; --pw: 56; --ph: 13;
  --vx: 22; --vy: 100; --vw: 56; --vh: 13;
  --r1: 20; --r2: 50; --r3: 80; --ry: 128; --rw: 14; --rh: 10; --rcap: 30;
  --bus: 118;
  --dx: 5; --dy: 157; --dd: 0.788;
  --cw: 12; --ch: 7.5;
  --lx: 50; --ly: 81; --l1x: 0; --l1y: -6; --l2x: 0; --l2y: -6; --l3x: 0; --l3y: -6;
  position: relative;
  aspect-ratio: 100 / var(--h);
  margin-top: 0.9rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--badge-wall);
  color: #fff;
  font-family: var(--font-sans);
  container-type: inline-size;
}

.badge-plan > *,
.badge-deck > *,
.badge-fx > * {
  position: absolute;
  margin: 0;
}

/* Names of the hardware, and what a part does. */
.badge-part {
  color: rgba(250, 250, 250, 0.66);
  font-size: clamp(0.56rem, 1.25vw, 0.66rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-does {
  display: block;
  color: rgba(250, 250, 250, 0.86);
  font-size: clamp(0.66rem, 1.5vw, 0.8rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.25;
  text-transform: none;
}

.badge-part--screen {
  left: 5cqw;
  top: 3.4cqw;
}

.badge-part--cards {
  left: calc(var(--dx) * 1cqw);
  top: calc((var(--dy) - 5.6) * 1cqw);
}

/* The round LED screen: the picture and a thin ring. */
.badge-led {
  left: calc((var(--sx) - var(--sd) / 2) * 1cqw);
  top: calc((var(--sy) - var(--sd) / 2) * 1cqw);
  width: calc(var(--sd) * 1cqw);
  aspect-ratio: 1;
  border-radius: 50%;
}

.badge-led::before,
.badge-led::after {
  content: "";
  position: absolute;
  inset: -0.34rem;
  border: 1px solid var(--badge-line);
  border-radius: 50%;
}

.badge-led::after {
  border-color: var(--badge-lit);
  opacity: 0;
}

.badge-spin {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 50%;
  background: #000;
}

.badge-visual {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The second, third and fourth pictures lie over the first and are shown by the animation. */
.badge-visual--next {
  opacity: 0;
}

/* The two photographs differ in colour as well as in shape. A shifted towards the colours of B, and B shifted
   towards the colours of A, give two shapes in two colours. */
.badge-visual--warm {
  filter: hue-rotate(58deg) saturate(1.25);
}

.badge-visual--cool {
  filter: hue-rotate(-62deg) saturate(1.2);
}

/* Cables, drawn once for each layout. */
.badge-wires {
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--badge-line);
  stroke-width: 2;
  stroke-linejoin: round;
  pointer-events: none;
}

.badge-wires--wide {
  display: none;
}

.badge-wires path {
  vector-effect: non-scaling-stroke;
}

.badge-wires .badge-live {
  stroke: var(--badge-lit);
  opacity: 0;
}

/* The computer and the server. */
.badge-computer,
.badge-server {
  left: calc(var(--px) * 1cqw);
  top: calc(var(--py) * 1cqw);
  display: grid;
  place-content: center;
  gap: 0.2rem;
  width: calc(var(--pw) * 1cqw);
  height: calc(var(--ph) * 1cqw);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: #0e0f12;
  text-align: center;
}

.badge-server {
  left: calc(var(--vx) * 1cqw);
  top: calc(var(--vy) * 1cqw);
  grid-auto-flow: column;
  align-items: center;
  gap: 0.7rem;
  width: calc(var(--vw) * 1cqw);
  height: calc(var(--vh) * 1cqw);
  text-align: left;
}

.badge-server-text {
  display: grid;
  gap: 0.2rem;
}

/* The log: reads per card. The card read most often has the colour of a card. */
.badge-stats {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 1.3rem;
  opacity: 0.5;
}

.badge-stats i {
  width: 3px;
  height: 45%;
  border-radius: 1px;
  background: rgba(250, 250, 250, 0.85);
}

.badge-stats i:nth-child(2) { height: 100%; background: hsl(32 100% 62%); }
.badge-stats i:nth-child(3) { height: 30%; }
.badge-stats i:nth-child(4) { height: 70%; }
.badge-stats i:nth-child(5) { height: 55%; }
.badge-stats i:nth-child(6) { height: 20%; }

.badge-computer::after,
.badge-server::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid var(--badge-lit);
  border-radius: inherit;
  opacity: 0;
}

/* The three readers, all the same size. */
.badge-reader {
  --rx: var(--r1);
  left: calc((var(--rx) - var(--rcap) / 2) * 1cqw);
  top: calc((var(--ry) - var(--rh) / 2) * 1cqw);
  display: grid;
  justify-items: center;
  width: calc(var(--rcap) * 1cqw);
  text-align: center;
}

.badge-reader--2 { --rx: var(--r2); }
.badge-reader--3 { --rx: var(--r3); }

.badge-reader svg {
  display: block;
  width: calc(var(--rw) * 1cqw);
  height: calc(var(--rh) * 1cqw);
  margin-bottom: clamp(0.3rem, 1.4cqw, 0.6rem);
  overflow: visible;
  fill: #0e0f12;
  stroke: rgba(250, 250, 250, 0.6);
  stroke-width: 1;
  stroke-linecap: round;
}

.badge-reader svg * {
  vector-effect: non-scaling-stroke;
}

.badge-reader svg path {
  fill: none;
}

.badge-reader svg .badge-reader-on {
  fill: none;
  stroke: var(--badge-lit);
  stroke-width: 1.5;
  opacity: 0;
}

/* The deck: 100 cards of the size of the card on a reader, each over the one before it. */
.badge-deck {
  inset: 0;
}

.badge-deck i,
.badge-card {
  left: calc((var(--dx) + var(--i) * var(--dd)) * 1cqw);
  top: calc(var(--dy) * 1cqw);
  width: calc(var(--cw) * 1cqw);
  height: calc(var(--ch) * 1cqw);
  border: 1px solid rgba(250, 250, 250, 0.5);
  border-radius: 0.14rem;
  background:
    linear-gradient(hsl(var(--h) 100% 62%), hsl(var(--h) 100% 62%)) 0 0 / 100% 36% no-repeat,
    #101114;
}

/* What moves: six cards and five signal points. */
.badge-fx {
  inset: 0;
  pointer-events: none;
}

/* A card: its number in the deck, its hue (the deck gives card n the hue n x 137 mod 360) and its reader. */
.badge-card {
  --rx: var(--r1);
  --tx: calc((var(--rx) - var(--cw) / 2 - var(--dx) - var(--i) * var(--dd)) * 1cqw);
  --ty: calc((var(--ry) - var(--ch) / 2 - var(--dy)) * 1cqw);
  opacity: 0;
}

.badge-card:nth-child(1) { --i: 16; --h: 32; opacity: 1; transform: translate(var(--tx), var(--ty)); }
.badge-card:nth-child(2) { --i: 38; --h: 166; --rx: var(--r2); }
.badge-card:nth-child(3) { --i: 60; --h: 300; --rx: var(--r3); }
.badge-card:nth-child(4) { --i: 74; --h: 58; }
.badge-card:nth-child(5) { --i: 25; --h: 185; --rx: var(--r2); }
.badge-card:nth-child(6) { --i: 89; --h: 313; --rx: var(--r3); }

.badge-dot {
  width: 0.5rem;
  height: 0.5rem;
  margin: -0.25rem 0 0 -0.25rem;
  border-radius: 50%;
  background: #f1f7ff;
  box-shadow: 0 0 6px 1px rgba(234, 244, 255, 0.75);
  opacity: 0;
}

/* From the top of a reader up to the joining line, along it, then into the server. */
.badge-dot--reader {
  --rx: var(--r1);
  --y0: calc(var(--ry) - var(--rh) / 2);
  --ax: calc((var(--vx) + var(--vw) / 2 - var(--rx)) * 1cqw);
  --a1: calc((var(--bus) - var(--y0)) * 1cqw);
  --a2: calc((var(--vy) + var(--vh) - var(--y0)) * 1cqw);
  left: calc(var(--rx) * 1cqw);
  top: calc(var(--y0) * 1cqw);
}

.badge-dot--reader:nth-child(8) { --rx: var(--r2); }
.badge-dot--reader:nth-child(9) { --rx: var(--r3); }

.badge-dot--link {
  left: calc(var(--lx) * 1cqw);
  top: calc(var(--ly) * 1cqw);
}

/* From the top of the server up into the computer. */
.badge-dot--relay {
  --b: calc((var(--py) + var(--ph) - var(--vy)) * 1cqw);
  left: calc((var(--vx) + var(--vw) / 2) * 1cqw);
  top: calc(var(--vy) * 1cqw);
}

/* The five steps, in words. The step being played has its number filled. */
.badge-steps {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 0;
  padding: 0;
  counter-reset: badge-step;
  list-style: none;
}

.badge-steps li {
  position: relative;
  padding-left: 2.1rem;
  color: var(--muted-foreground);
  font-size: 0.92rem;
  line-height: 1.45;
  counter-increment: badge-step;
}

.badge-steps li::before,
.badge-steps li::after {
  position: absolute;
  top: 0.05rem;
  left: 0;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  content: "";
}

.badge-steps li::before {
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  color: var(--foreground);
  font-size: 0.74rem;
  font-weight: 600;
  content: counter(badge-step);
}

.badge-steps li::after {
  background: rgba(255, 255, 255, 0.24);
  opacity: 0;
}

/* Wide screens: the screen on the left; the computer, the server, the readers and the cards on the right. */
@media (min-width: 641px) {
  .badge-plan {
    --h: 52;
    --sx: 25; --sy: 26; --sd: 38;
    --px: 60; --py: 4; --pw: 28; --ph: 7;
    --vx: 60; --vy: 15; --vw: 28; --vh: 7;
    --r1: 60; --r2: 74; --r3: 88; --ry: 30.5; --rw: 6; --rh: 4.4; --rcap: 14;
    --bus: 25.5;
    --dx: 54; --dy: 43.5; --dd: 0.3535;
    --cw: 5; --ch: 3.2;
    --lx: 60; --ly: 7.5; --l1x: -11; --l1y: 0; --l2x: -11; --l2y: 18.5; --l3x: -16; --l3y: 18.5;
  }

  .badge-part--screen {
    left: 3cqw;
    top: 2.6cqw;
  }

  .badge-part--cards {
    top: calc((var(--dy) - 2.7) * 1cqw);
  }

  .badge-wires--phone {
    display: none;
  }

  .badge-wires--wide {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .badge-reader--1 .badge-reader-on,
  .badge-live--r1,
  .badge-live--relay,
  .badge-live--link {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .badge-card {
    animation: badge-card 21s linear infinite both;
  }

  .badge-card:nth-child(2) { animation-delay: 3.5s; }
  .badge-card:nth-child(3) { animation-delay: 7s; }
  .badge-card:nth-child(4) { animation-delay: 10.5s; }
  .badge-card:nth-child(5) { animation-delay: 14s; }
  .badge-card:nth-child(6) { animation-delay: 17.5s; }

  .badge-reader-on { animation: badge-reader 10.5s linear infinite both; }
  .badge-live--reader { animation: badge-wire 10.5s linear infinite both; }
  .badge-dot--reader { animation: badge-signal 10.5s linear infinite both; }

  .badge-reader--2 .badge-reader-on,
  .badge-live--r2,
  .badge-dot--reader:nth-child(8) { animation-delay: 3.5s; }

  .badge-reader--3 .badge-reader-on,
  .badge-live--r3,
  .badge-dot--reader:nth-child(9) { animation-delay: 7s; }

  .badge-server::after { animation: badge-server 3.5s linear infinite both; }
  .badge-stats { animation: badge-stats 3.5s linear infinite both; }
  .badge-live--relay { animation: badge-relay 3.5s linear infinite both; }
  .badge-dot--relay { animation: badge-relay-dot 3.5s linear infinite both; }
  .badge-computer::after { animation: badge-computer 3.5s linear infinite both; }
  .badge-live--link { animation: badge-link 3.5s linear infinite both; }
  .badge-dot--link { animation: badge-link-dot 3.5s linear infinite both; }
  .badge-led::after { animation: badge-ring 3.5s linear infinite both; }

  .badge-visual--a2 { animation: badge-visual-a2 21s linear infinite both; }
  .badge-visual--b1 { animation: badge-visual-b1 21s linear infinite both; }
  .badge-visual--b2 { animation: badge-visual-b2 21s linear infinite both; }
  .badge-spin { animation: badge-spin 21s linear infinite both; }

  .badge-steps li::after { animation: badge-step-1 3.5s linear infinite both; }
  .badge-steps li:nth-child(2)::after { animation-name: badge-step-2; }
  .badge-steps li:nth-child(3)::after { animation-name: badge-step-3; }
  .badge-steps li:nth-child(4)::after { animation-name: badge-step-4; }
  .badge-steps li:nth-child(5)::after { animation-name: badge-step-5; }
}

/* A card: it lifts out of the deck, lands on its reader, waits for the picture to change, then fades. */
@keyframes badge-card {
  0% { opacity: 0; transform: translate(0, 0); }
  0.7% { opacity: 1; transform: translate(0, 0); }
  1.5% { opacity: 1; transform: translate(0, -1.6cqw); animation-timing-function: cubic-bezier(0.5, 0, 0.2, 1); }
  4.5% { opacity: 1; transform: translate(var(--tx), var(--ty)); }
  13.7% { opacity: 1; transform: translate(var(--tx), var(--ty)); }
  15%, 100% { opacity: 0; transform: translate(var(--tx), var(--ty)); }
}

@keyframes badge-reader {
  0%, 9.7% { opacity: 0; }
  10.3%, 26.7% { opacity: 1; }
  29.3%, 100% { opacity: 0; }
}

@keyframes badge-wire {
  0%, 10.7% { opacity: 0; }
  11.3%, 15.7% { opacity: 1; }
  18.3%, 100% { opacity: 0; }
}

@keyframes badge-signal {
  0%, 10.5% { opacity: 0; transform: translate(0, 0); }
  10.7% { opacity: 1; transform: translate(0, 0); }
  12% { opacity: 1; transform: translate(0, var(--a1)); }
  14% { opacity: 1; transform: translate(var(--ax), var(--a1)); }
  15% { opacity: 1; transform: translate(var(--ax), var(--a2)); }
  15.7%, 100% { opacity: 0; transform: translate(var(--ax), var(--a2)); }
}

/* The server receives the read and logs it. */
@keyframes badge-server {
  0%, 43% { opacity: 0; }
  46%, 56% { opacity: 1; }
  64%, 100% { opacity: 0; }
}

@keyframes badge-stats {
  0%, 43% { opacity: 0.5; }
  46%, 60% { opacity: 1; }
  72%, 100% { opacity: 0.5; }
}

@keyframes badge-relay {
  0%, 46% { opacity: 0; }
  48%, 55% { opacity: 1; }
  62%, 100% { opacity: 0; }
}

@keyframes badge-relay-dot {
  0%, 47% { opacity: 0; transform: translate(0, 0); }
  48% { opacity: 1; transform: translate(0, 0); }
  53% { opacity: 1; transform: translate(0, var(--b)); }
  55%, 100% { opacity: 0; transform: translate(0, var(--b)); }
}

@keyframes badge-computer {
  0%, 52% { opacity: 0; }
  55%, 66% { opacity: 1; }
  74%, 100% { opacity: 0; }
}

@keyframes badge-link {
  0%, 55% { opacity: 0; }
  57%, 68% { opacity: 1; }
  76%, 100% { opacity: 0; }
}

/* On the phone the three legs are one: the cable runs straight up. */
@keyframes badge-link-dot {
  0%, 56% { opacity: 0; transform: translate(0, 0); }
  57% { opacity: 1; transform: translate(0, 0); }
  60.5% { opacity: 1; transform: translate(calc(var(--l1x) * 1cqw), calc(var(--l1y) * 1cqw)); }
  65.5% { opacity: 1; transform: translate(calc(var(--l2x) * 1cqw), calc(var(--l2y) * 1cqw)); }
  67.5% { opacity: 1; transform: translate(calc(var(--l3x) * 1cqw), calc(var(--l3y) * 1cqw)); }
  69.5%, 100% { opacity: 0; transform: translate(calc(var(--l3x) * 1cqw), calc(var(--l3y) * 1cqw)); }
}

@keyframes badge-ring {
  0%, 66% { opacity: 0; }
  70% { opacity: 0.9; }
  90%, 100% { opacity: 0; }
}

/* The pictures. Bottom to top: A, A in the colours of B, B, B in the colours of A. Each slot lasts 3.5 s and the
   picture changes 2.35 s into it. A reader changes one aspect and leaves the two others as they are.
   Slot 1: reader 1 changes the shape, A to B.      Slot 2: reader 2 changes the colour of B.
   Slot 3: reader 3 changes the movement, a turn.   Slot 4: reader 1 changes the shape back to A.
   Slot 5: reader 2 brings the first colour back.   Slot 6: reader 3 turns the picture again.
   At 20% the top picture hides the two under it, so they are switched on there without a visible step. */
@keyframes badge-visual-a2 {
  0%, 20% { opacity: 0; }
  20.1%, 77.83% { opacity: 1; }
  80.67%, 100% { opacity: 0; }
}

@keyframes badge-visual-b1 {
  0%, 20% { opacity: 0; }
  20.1%, 61.17% { opacity: 1; }
  64%, 100% { opacity: 0; }
}

@keyframes badge-visual-b2 {
  0%, 11.17% { opacity: 0; }
  14%, 27.83% { opacity: 1; }
  30.67%, 100% { opacity: 0; }
}

@keyframes badge-spin {
  0%, 44.5% { transform: rotate(0deg); animation-timing-function: ease-in-out; }
  50%, 94.5% { transform: rotate(180deg); animation-timing-function: ease-in-out; }
  100% { transform: rotate(360deg); }
}

/* The steps, in each slot: the card leaves the deck, lies on the reader, the read reaches the server, the server
   passes it to the browser, the picture changes. */
@keyframes badge-step-1 { 0%, 26% { opacity: 1; } 28%, 97% { opacity: 0; } 100% { opacity: 1; } }
@keyframes badge-step-2 { 0%, 26% { opacity: 0; } 28%, 41% { opacity: 1; } 43%, 100% { opacity: 0; } }
@keyframes badge-step-3 { 0%, 41% { opacity: 0; } 43%, 52% { opacity: 1; } 54%, 100% { opacity: 0; } }
@keyframes badge-step-4 { 0%, 52% { opacity: 0; } 54%, 66% { opacity: 1; } 68%, 100% { opacity: 0; } }
@keyframes badge-step-5 { 0%, 66% { opacity: 0; } 68%, 97% { opacity: 1; } 100% { opacity: 0; } }
