/* Coin turn: a real coin that turns over as the page scrolls.
   Everything that moves per frame is a transform or an opacity, so the browser
   composites it without laying out or painting. The rim is a ring of thin slats
   fitted to the coin's own outline (built by coin-turn.js), so there is nothing
   stacked behind the faces that could ghost. */

.coin-turn {
  /* the host sets the size; the coin fills it */
  position: relative;
  display: block;
  width: var(--coin-size, 420px);
  aspect-ratio: 1;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;         /* the page keeps vertical scroll on touch */
  perspective: var(--coin-perspective, 1400px);
  perspective-origin: 50% 50%;
  outline-offset: 10px;
}
.coin-turn:focus-visible { outline: 2px solid var(--coin-focus, currentColor); border-radius: 50%; }

/* the cast shadow lives on the wall behind, outside the 3D stage */
.coin-turn__cast {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--coin-shadow, rgba(20, 26, 28, 0.42)), transparent 100%);
  filter: blur(var(--coin-shadow-blur, 16px));
  transform: translate(8%, 10%) scaleX(0.95);
  transform-origin: 50% 50%;
  opacity: 0.9;
  pointer-events: none;
  will-change: transform, opacity;
}

/* the 3D stage: faces and rim turn together; the gloss stage carries the two
   specular planes and takes the same transform */
.coin-turn__stage, .coin-turn__gloss {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(6deg) rotateY(-18deg);
  will-change: transform;
}

.coin-turn__face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* the rim: one slat per few degrees, each a flat strip standing on the outline.
   Shading is baked per slat from its angle (light from the upper left). */
.coin-turn__rim {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}
.coin-turn__slat {
  position: absolute;
  left: 50%;
  top: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: rgb(96, 90, 80);
  /* The struck edge is rounded: darker where it turns into each face, a soft line of
     light along the middle. No milling pattern, these coins were struck by hand. The
     per-slat colour from shadeRim shows through underneath. */
  background-image:
    linear-gradient(to bottom, rgba(0,0,0,0.46), rgba(0,0,0,0.12) 24%, rgba(255,255,255,0.09) 50%, rgba(0,0,0,0.10) 76%, rgba(0,0,0,0.46));
}

/* a specular that slides across the metal as it turns; masked to the coin's own shape.
   No blend mode: a blend inside a preserve-3d stage makes Chrome flatten the stage
   and the rim vanishes behind the faces. */
.coin-turn__gloss { pointer-events: none; }
.coin-turn__shine {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  -webkit-mask-size: contain; mask-size: contain;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  opacity: 0.6;
}
.coin-turn__shine > i {
  position: absolute;
  top: -20%;
  left: -10%;
  width: 55%;
  height: 140%;
  background: linear-gradient(100deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.10) 35%,
    rgba(255, 255, 255, 0.38) 50%,
    rgba(255, 255, 255, 0.10) 65%,
    rgba(255, 255, 255, 0) 100%);
  transform: translateX(-60%);
  will-change: transform;
}

/* while the rim is being built (first paint, before the images decode) hide it so
   nothing half-made shows */
.coin-turn:not(.is-ready) .coin-turn__rim { visibility: hidden; }

@media (prefers-reduced-motion: reduce) {
  .coin-turn__cast, .coin-turn__stage, .coin-turn__gloss, .coin-turn__shine > i { will-change: auto; }
}
