﻿/* ---------- Victory Treasure Chest (module prefix: chst-) ----------
   Full-screen celebration overlay appended to .board by 16-chest.js. Uses the chalkboard
   design tokens from styles.css (--ink/--chalk/--yellow/--wood...). Every class is prefixed
   chst- to avoid collisions. All animations are disabled under prefers-reduced-motion (the JS
   also skips its stagger timers, so everything just appears in its final state). */

.chst-overlay{
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(12, 26, 19, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  animation: chst-fade 0.25s ease both;
}
@keyframes chst-fade{
  from{ opacity: 0; }
  to{ opacity: 1; }
}

.chst-stage{
  text-align: center;
  padding: 16px;
  max-width: 460px;
}

.chst-title{
  font-family: 'Patrick Hand', cursive;
  font-size: 42px;
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(242, 193, 78, 0.35);
  margin-bottom: 4px;
}

/* --- the chest --- */
.chst-chest{
  position: relative;
  display: inline-block;
  cursor: pointer;
  outline: none;
  animation: chst-drop 0.9s cubic-bezier(0.3, 0.9, 0.4, 1) both;
}
.chst-chest:focus-visible{
  filter: drop-shadow(0 0 8px rgba(110, 193, 228, 0.8)); /* --sky glow for keyboard users */
}
.chst-svg{
  width: min(230px, 58vw);
  height: auto;
  display: block;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}
@keyframes chst-drop{
  0%   { transform: translateY(-420px); }
  55%  { transform: translateY(0); }
  70%  { transform: translateY(-30px); }
  84%  { transform: translateY(0); }
  92%  { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

/* the lid flips open around a hinge at viewBox point (22,52) â€” see chstChestSvg() */
.chst-lid{
  transform-box: view-box;
  transform-origin: 22px 52px;
  transition: transform 0.5s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.chst-open .chst-lid{
  transform: rotate(-76deg);
}

/* golden treasure glow revealed under the lid */
.chst-glow{
  opacity: 0;
  transition: opacity 0.4s ease 0.12s;
}
.chst-open .chst-glow{
  opacity: 0.95;
}

/* --- "Tap to open!" prompt --- */
.chst-prompt{
  font-family: 'Patrick Hand', cursive;
  font-size: 26px;
  color: var(--chalk);
  margin-top: 6px;
  animation: chst-bob 1.2s ease-in-out infinite;
}
.chst-open .chst-prompt{
  display: none;
}
@keyframes chst-bob{
  0%, 100%{ transform: translateY(0); }
  50%     { transform: translateY(-7px); }
}

/* --- sparkle burst on open --- */
.chst-spark-layer{
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.chst-spark{
  position: absolute;
  left: 50%;
  top: 38%;
  font-size: 19px;
  opacity: 0;
  pointer-events: none;
  animation: chst-spark-fly 0.9s ease-out both;
  animation-delay: var(--delay, 0s);
}
@keyframes chst-spark-fly{
  0%{
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100%{
    opacity: 0;
    transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -60px))) scale(1.3);
  }
}

/* --- reward chips (ðŸ’µ + one per material) --- */
.chst-chips{
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 16px auto 6px;
  min-height: 48px;
}
.chst-chip{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(244, 241, 232, 0.1);
  border: 2px solid rgba(242, 193, 78, 0.5);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 19px;
  color: var(--chalk);
  opacity: 0;               /* hidden until the JS adds .chst-in (staggered) */
  transform: translateY(30px) scale(0.4);
}
.chst-chip.chst-in{
  animation: chst-chip-pop 0.55s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}
@keyframes chst-chip-pop{
  0%  { opacity: 0; transform: translateY(34px) scale(0.3); }
  60% { opacity: 1; transform: translateY(-6px) scale(1.08); }
  100%{ opacity: 1; transform: translateY(0) scale(1); }
}
.chst-chip-icon{
  font-size: 24px;
  line-height: 1;
}
.chst-chip-label{
  color: var(--yellow);
}

/* --- Collect! button (reuses global .btn .btn-primary; this only handles the reveal) --- */
.chst-collect{
  visibility: hidden;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s ease, transform 0.3s ease;
  margin-top: 8px;
  font-size: 20px;
}
.chst-collect.chst-show{
  visibility: visible;
  opacity: 1;
  transform: scale(1);
}

/* --- narrow screens --- */
@media (max-width: 640px){
  .chst-title{ font-size: 32px; }
  .chst-svg{ width: min(180px, 54vw); }
  .chst-prompt{ font-size: 22px; }
  .chst-chip{ font-size: 16px; padding: 6px 12px; }
  .chst-chip-icon{ font-size: 20px; }
  .chst-collect{ font-size: 17px; }
}

/* --- reduced motion: no animation, everything in its final state --- */
@media (prefers-reduced-motion: reduce){
  .chst-overlay,
  .chst-chest,
  .chst-prompt,
  .chst-chip.chst-in{
    animation: none !important;
  }
  .chst-lid,
  .chst-glow,
  .chst-collect{
    transition: none !important;
  }
  .chst-chip.chst-in{
    opacity: 1;
    transform: none;
  }
  .chst-spark{
    display: none;
  }
}
