/* Cards and spreads.

   Structure built by js/app.js, relied on by js/draw-animation.js:

   <div class="spread">                    the spread, sized from its layout
     <div class="spread__area">            positioning box (card shapes only)
       <a class="slot" href="#card-…">     position in the spread (layout only)
         <div class="card">                may be moved by the animation
           <div class="card__inner">       turns over (rotateY) to reveal
             <div class="card__face card__back"><img></div>
             <div class="card__face card__front"><img></div>
           </div>
           <p class="card__label">Passé</p>   single-row spreads only
         </div>
         <span class="slot__number">1</span>  other spreads, instead of labels
       </a>
     </div>
   </div>

   Who may transform what:
   - .slot: the spread layout (left / top / width from the spread's layout,
     rotation in --rotate: the crossing card of the Celtic cross is a
     rotated slot). Never the animation.
   - .card and .card__inner: the draw animation only.
   - .card__front content: a reversed card (.card--reversed) is turned
     upside down there, so the flip and the layout don't have to know.
   - .is-revealed on .card: the resting "face up" state, set by the
     animation when it ends. On .spread: every card is face up.

   Sizes: js/app.js sets --spread-width / --spread-height (the spread's size
   in card widths, see layoutSpread in logic.js) and --card-ratio (the deck's
   card width / height). A card is at most --card-max wide, and the spread
   never wider than the screen, so the Celtic cross fits a 375 px screen. */

.spread {
  --card-max: 10rem;
  width: min(100%, calc(var(--spread-width, 1) * var(--card-max)), 36rem);
  margin: 0 auto;
}

/* Room for labels of up to two lines (see .card__label). */
.spread--labels {
  padding-bottom: 3rem;
}

.spread__area {
  position: relative;
  aspect-ratio: var(--spread-width, 1) / var(--spread-height, 1.7);
}

.slot {
  position: absolute;
  display: block;
  color: inherit;
  text-decoration: none;
  transform: rotate(var(--rotate, 0deg));
  -webkit-touch-callout: none;
}

.slot:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 8px;
}

.slot__number {
  position: absolute;
  top: -8px;
  left: -8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 700;
  /* Stays upright on a rotated slot. */
  transform: rotate(calc(-1 * var(--rotate, 0deg)));
  opacity: 0;
  transition: opacity 0.3s;
}

/* A 44 px tap target around the badge: in the Celtic cross, the crossing
   card covers most of card 1, and the badge is the easiest way to reach it. */
.slot__number::before {
  content: "";
  position: absolute;
  inset: -11px;
}

.spread.is-revealed .slot__number {
  opacity: 1;
}

.card {
  perspective: 900px;
}

.card__inner {
  position: relative;
  /* Set from the deck's cardSize; Rider-Waite cards are about 7 by 12. */
  aspect-ratio: var(--card-ratio, 7 / 12);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.card.is-revealed .card__inner {
  transform: rotateY(180deg);
}

.card__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 6px 18px rgb(0 0 0 / 45%);
}

/* Card back: the deck's back image, over a pattern drawn in CSS that shows
   when the image can't load (app.js removes a failed image). */
.card__back {
  border: 2px solid var(--accent);
  background:
    radial-gradient(circle at 50% 50%, rgb(217 180 90 / 35%) 0 14%, transparent 15%),
    repeating-linear-gradient(45deg, rgb(217 180 90 / 12%) 0 2px, transparent 2px 10px),
    repeating-linear-gradient(-45deg, rgb(217 180 90 / 12%) 0 2px, transparent 2px 10px),
    var(--surface-raised);
  outline: 1px solid rgb(217 180 90 / 40%);
  outline-offset: -7px;
}

.card__back:has(img) {
  border: 0;
  outline: 0;
}

.card__face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__front {
  transform: rotateY(180deg);
  display: grid;
  place-items: center;
  background: var(--text);
  color: var(--bg);
}

.card--reversed .card__front > * {
  transform: rotate(180deg);
}

/* Front without its image (offline before the images are precached): the
   card's name. */
.card__placeholder {
  padding: 4px;
  font-family: var(--font-display);
  font-size: 0.875rem;
  line-height: 1.2;
  text-align: center;
}

.card__label {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.875rem;
  line-height: 1.2;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
