/* Story Sparks, digital (play/story_sparks.templ).
   The cards are Boredom Buster's (boredom-buster.css): a bright card in a
   thick white rim, Fredoka, the pile in the corner, the picture, and a wave
   at the foot carrying the words.
   Phone: three cards stacked, the deal button pinned under the thumb.
   ≥760px: the cards are dealt side by side like a hand on a table, and the
   button moves up beside the intro. The rules are the page's to add, with an
   Activity block.
   The cards always share one size — the table's rows (phone) or columns
   (wide) are equal, so every card matches the tallest and none is clipped. */
.sparks {
  --sp-font: "Fredoka", "Montserrat", system-ui, sans-serif;
}
.sparks-lede {
  margin: 0 0 1rem;
  max-width: 46ch;
  color: var(--slate);
  font-size: 0.95rem;
  line-height: 1.45;
}

/* ---- The table ------------------------------------------------------- */
.sparks-table {
  display: grid;
  grid-auto-rows: minmax(13.5rem, 1fr);
  gap: 1rem;
}

/* One card per pile, in Boredom Buster's colours: --c is the card, --band
   the wave at its foot, --ink what reads on both. Yellow takes a dark ink. */
.sparks-card {
  --c: #9160f5;
  --band: #6b3bd8;
  --ink: #fff;
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-family: var(--sp-font);
  color: inherit;
  text-align: center;
  cursor: pointer;
  transform-style: preserve-3d;
  /* perspective() in the transform itself, so each card turns about its own
     centre; without it rotateY just squashes the card flat. Keep the 0.55s in
     step with FLIP in story-sparks.js. */
  transform: perspective(1400px) rotateY(0deg);
  transition: transform 0.55s cubic-bezier(0.45, 0.05, 0.2, 1);
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}
.sparks-card--1 { --c: #1f94e0; --band: #1168ad; }
.sparks-card--2 { --c: #ffd23a; --band: #ffa51f; --ink: #4a2208; }
.sparks-card.is-up { transform: perspective(1400px) rotateY(180deg); }
.sparks-card:focus-visible { outline: none; }
.sparks-card:focus-visible > span { outline: 3px solid var(--teal-hover); outline-offset: 4px; }

.sparks-back,
.sparks-face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 4px solid #fff;
  border-radius: 22px;
  overflow: hidden;
  color: var(--ink);
  box-shadow: 0 14px 32px rgba(26, 56, 40, 0.18);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Face down: the pile's colour under a dot screen, its mark bobbing in a
   white coin, as Boredom Buster's "?" does. */
.sparks-back {
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 1rem;
  background:
    radial-gradient(circle at 2px 2px, rgba(255, 255, 255, 0.3) 1.6px, transparent 0) 0 0 / 16px 16px,
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.3), transparent 60%),
    var(--c);
  transition: box-shadow 0.2s ease;
}
.sparks-back-mark {
  display: grid;
  place-items: center;
  width: 4.25rem;
  aspect-ratio: 1;
  margin-bottom: 0.35rem;
  border-radius: 50%;
  background: #fff;
  font-size: 2.2rem;
  line-height: 1;
  box-shadow: 0 5px 0 rgba(26, 56, 40, 0.15);
  animation: sparks-bob 2.4s ease-in-out infinite;
}
.sparks-card--1 .sparks-back-mark { animation-delay: -0.8s; }
.sparks-card--2 .sparks-back-mark { animation-delay: -1.6s; }
.sparks-back-name {
  font-size: clamp(1.6rem, 7vw, 1.95rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 color-mix(in srgb, var(--band) 60%, transparent);
}
.sparks-back-question { font-size: 0.95rem; font-weight: 500; }
.sparks-back-hint {
  margin-top: 0.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: #fff;
  color: var(--forest);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.is-shuffling .sparks-back { animation: sparks-shuffle 0.4s ease-in-out; }

@media (hover: hover) {
  .sparks-card:hover .sparks-back { box-shadow: 0 18px 40px rgba(26, 56, 40, 0.24); }
}

/* Face up: the pile in the corner, the picture on a soft glow, then the
   wave with the words on it. */
.sparks-face {
  position: relative;
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.38), transparent 55%),
    var(--c);
}
.sparks-index {
  position: absolute;
  top: 0.7rem;
  left: 0.9rem;
  color: color-mix(in srgb, var(--band) 45%, #2a0a0a);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sparks-card--0 .sparks-index { color: #fff; }
.sparks-art {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 1.9rem 0 1.5rem;
  font-size: clamp(2.6rem, 12vw, 3rem);
  line-height: 1;
  filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.14));
}
/* Every picture stands in a white coin: the hero's drawing so its colours
   never fight the card's, the emoji so they don't sink into it. */
.sparks-coin {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(5.5rem, 26vw, 6.5rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
}
.sparks-coin img { position: absolute; inset: 0; width: 100%; height: 100%; }

.sparks-foot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.3rem 1rem 1rem;
  background: var(--band);
}
.sparks-wave {
  position: absolute;
  left: 0;
  bottom: calc(100% - 1px);
  width: 100%;
  height: 1.6rem;
  fill: var(--band);
}
.sparks-wave-soft { opacity: 0.45; }
.sparks-badge {
  position: absolute;
  right: 0.8rem;
  top: -2.1rem;
  display: grid;
  place-items: center;
  width: 2.75rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff;
  font-size: 1.35rem;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}
.sparks-text {
  font-size: clamp(1.15rem, 5vw, 1.3rem);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
  overflow-wrap: break-word;
}
.sparks-more { font-size: 0.95rem; font-weight: 500; line-height: 1.3; opacity: 0.9; text-wrap: balance; }

@keyframes sparks-shuffle {
  0%, 100% { transform: none; }
  20% { transform: translateX(-6px) rotate(-2.5deg); }
  45% { transform: translateX(6px) rotate(2deg); }
  70% { transform: translateX(-3px) rotate(-1deg); }
}
@keyframes sparks-bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-5px) rotate(4deg); }
}

/* ---- Deal button: Boredom Buster's pill, under the thumb ---------------- */
.sparks-bar {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 0.4rem calc(-1 * var(--pad)) 0;
  padding: 0.75rem var(--pad) calc(0.9rem + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(247, 245, 240, 0), var(--warm-white) 35%);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}
.sparks-bar:not(.is-ready) { opacity: 0; visibility: hidden; transform: translateY(0.4rem); }
.sparks-deal {
  display: block;
  width: 100%;
  min-height: 3.25rem;
  padding: 0 1.75rem;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: 700 17px/1 "Montserrat", Helvetica, Arial, sans-serif;
  cursor: pointer;
  transition: filter 0.15s;
}
.sparks-deal:hover { filter: brightness(1.12); }
.sparks-deal:focus-visible { outline: 2px solid var(--teal-hover); outline-offset: 3px; }

/* ---- Wide screens: the hand laid out on the table -------------------- */
@media (min-width: 760px) {
  .sparks {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "lede deal"
      "table table";
    align-items: end;
    column-gap: 2rem;
  }
  .sparks-lede { grid-area: lede; max-width: 52ch; margin: 0; font-size: 1.05rem; }
  .sparks-bar {
    grid-area: deal;
    position: static;
    margin: 0 0 6px;
    padding: 0;
    background: none;
  }
  .sparks-deal { width: auto; }

  .sparks-table {
    grid-area: table;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-auto-rows: minmax(clamp(21rem, 34vw, 27rem), 1fr);
    gap: clamp(1rem, 2.4vw, 2rem);
    margin: 1.75rem 0 2rem;
  }
  /* A hand, not a grid: the outer two lean out a little. */
  .sparks-card--0 { rotate: -2deg; }
  .sparks-card--2 { rotate: 2deg; }
  .sparks-back-mark { width: 5.5rem; font-size: 2.9rem; }
  .sparks-back-name { font-size: clamp(1.9rem, 3vw, 2.3rem); }
  .sparks-index { font-size: 1.2rem; }
  .sparks-art { font-size: clamp(3.75rem, 6vw, 4.75rem); }
  .sparks-coin { width: min(62%, 10rem); }
  .sparks-foot { padding: 0.4rem 1.1rem 1.3rem; gap: 0.35rem; }
  .sparks-text { font-size: clamp(1.2rem, 1.9vw, 1.45rem); }
  .sparks-more { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .sparks-card,
  .sparks-bar { transition: none; }
  .is-shuffling .sparks-back,
  .sparks-back-mark { animation: none; }
}
