/* Game 1: Catch the magical hearts. HTML overlay above the 3D island. */
.hg {
  --plum: #24143d;
  --pink: #f4a9c6;
  --rose: #c45f93;
  --gold: #ffd76a;
  --cream: #fff5e6;
  --ease-out: cubic-bezier(0.05, 0.7, 0.1, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-pop: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: fixed;
  inset: 0;
  z-index: 6;
  color: var(--cream);
  font-family: Figtree, system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  opacity: 0;
  transition: opacity 0.6s var(--ease-soft);
}
.hg[hidden] { display: none; }
.hg.is-on { opacity: 1; }

/* ---------- HUD ---------- */
.hg-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(0.9rem, env(safe-area-inset-top)) max(1.1rem, env(safe-area-inset-right)) 1.6rem max(1.1rem, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(36, 20, 61, 0.72), rgba(36, 20, 61, 0));
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title score" "lights time";
  align-items: end;
  row-gap: 0.55rem;
  column-gap: 1rem;
  pointer-events: none;
  transform: translateY(-12px);
  transition: transform 0.6s var(--ease-out);
}
.hg.is-on .hg-hud { transform: none; }
.hg-title {
  grid-area: title;
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 500;
  font-size: clamp(1.15rem, 3.6vw, 1.6rem);
  line-height: 1.1;
  text-shadow: 0 2px 12px rgba(18, 8, 36, 0.6);
}
.hg-score {
  grid-area: score;
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 215, 106, 0.35);
}
.hg-score small { font-size: 0.6em; color: var(--cream); opacity: 0.7; font-weight: 500; }

/* the progress: a string of ten fairy-light hearts on a gold thread */
.hg-lights {
  grid-area: lights;
  position: relative;
  display: flex;
  gap: clamp(0.18rem, 1.2vw, 0.45rem);
  margin: 0;
  padding: 0;
  list-style: none;
}
.hg-lights::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 2px;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 215, 106, 0.7), rgba(255, 215, 106, 0.15));
}
.hg-light {
  position: relative;
  width: clamp(18px, 5.4vw, 24px);
  height: clamp(18px, 5.4vw, 24px);
  margin-top: 4px;
}
.hg-light svg { width: 100%; height: 100%; display: block; overflow: visible; }
.hg-light .hg-shape { fill: rgba(255, 245, 230, 0.08); stroke: rgba(255, 245, 230, 0.45); stroke-width: 1.2; }
.hg-light.is-lit .hg-shape { fill: url(#hg-fill); stroke: var(--gold); stroke-width: 1; }
.hg-light.is-lit { filter: drop-shadow(0 0 6px rgba(244, 169, 198, 0.85)); animation: hg-lightpop 0.42s var(--ease-pop); }
@keyframes hg-lightpop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.hg-time {
  grid-area: time;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.hg-thread {
  width: clamp(64px, 16vw, 120px);
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 245, 230, 0.16);
  overflow: hidden;
}
.hg-thread i {
  display: block;
  height: 100%;
  background: var(--gold);
  transform-origin: 0 50%;
  box-shadow: 0 0 8px rgba(255, 215, 106, 0.7);
}

/* ---------- play field ---------- */
.hg-field { position: absolute; inset: 0; overflow: hidden; cursor: none; }
.hg:not(.is-playing) .hg-field { cursor: default; }

.hg-heart {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--hs, 52px);
  height: var(--hs, 52px);
  margin: calc(var(--hs, 52px) / -2) 0 0 calc(var(--hs, 52px) / -2);
  will-change: transform, opacity;
  filter: drop-shadow(0 0 10px rgba(244, 169, 198, 0.75)) drop-shadow(0 4px 6px rgba(36, 20, 61, 0.45));
  pointer-events: none;
}
.hg-heart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.hg-heart .hg-token { fill: url(#hg-fill); stroke: #ffd76a; stroke-width: 0.9; }
.hg-heart.is-magnetic { filter: drop-shadow(0 0 14px rgba(255, 215, 106, 0.9)) drop-shadow(0 4px 6px rgba(36, 20, 61, 0.45)); }
.hg-heart.is-missed { transition: opacity 0.7s var(--ease-soft); opacity: 0; }

.hg-basket {
  position: absolute;
  left: 0;
  bottom: calc(env(safe-area-inset-bottom) + clamp(18px, 7vh, 64px));
  width: var(--bw, 168px);
  margin-left: calc(var(--bw, 168px) / -2);
  will-change: transform;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(18, 8, 36, 0.55));
}
.hg-basket svg { width: 100%; height: auto; display: block; overflow: visible; }
.hg-basket .hg-body { transform-origin: 50% 100%; transform-box: fill-box; }
.hg-basket.is-catch .hg-body { animation: hg-squash 0.32s var(--ease-pop); }
@keyframes hg-squash {
  0% { transform: scale(1, 1); }
  35% { transform: scale(1.07, 0.9); }
  100% { transform: scale(1, 1); }
}
.hg-basket::after {
  /* soft lamp-glow under the basket, so it feels set on the island */
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -10px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 215, 106, 0.45), rgba(255, 215, 106, 0));
}

.hg-spark {
  position: absolute;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  pointer-events: none;
  background: radial-gradient(closest-side, #fff8dc, var(--gold) 45%, rgba(255, 215, 106, 0));
  border-radius: 50%;
  animation: hg-spark 0.6s var(--ease-out) forwards;
}
@keyframes hg-spark {
  from { transform: translate(var(--x0), var(--y0)) scale(1); opacity: 1; }
  to { transform: translate(var(--x1), var(--y1)) scale(0.3); opacity: 0; }
}

/* ---------- hint + cards ---------- */
.hg-hint {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + clamp(18px, 7vh, 64px) + var(--bh, 100px) + 14px);
  transform: translateX(-50%);
  margin: 0;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: rgba(36, 20, 61, 0.6);
  border: 1px solid rgba(255, 215, 106, 0.35);
  font-size: 0.86rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s var(--ease-soft);
}
.hg-hint.is-on { opacity: 1; }

.hg-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(88vw, 23rem);
  padding: 1.5rem 1.4rem 1.35rem;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, rgba(52, 30, 86, 0.86), rgba(36, 20, 61, 0.9));
  border: 1px solid rgba(255, 215, 106, 0.4);
  box-shadow: 0 24px 60px rgba(12, 4, 26, 0.55), inset 0 1px 0 rgba(255, 245, 230, 0.12);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transform: translate(-50%, calc(-50% + 18px)) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease-soft), transform 0.5s var(--ease-out);
}
.hg-card.is-on { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }
.hg-card h2 {
  margin: 0 0 0.5rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  font-size: clamp(1.55rem, 6vw, 2rem);
  line-height: 1.1;
}
.hg-card h2.hg-script {
  font-family: "Great Vibes", "Cormorant Garamond", cursive;
  font-weight: 400;
  font-size: clamp(2.3rem, 10vw, 3.1rem);
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 215, 106, 0.35);
}
.hg-card p {
  margin: 0 auto 1.15rem;
  max-width: 30ch;
  font-size: 0.98rem;
  line-height: 1.5;
  opacity: 0.88;
}
.hg-card p:last-child { margin-bottom: 0; }
.hg-btn {
  font: 600 1rem Figtree, system-ui, sans-serif;
  min-height: 52px;
  min-width: 10rem;
  padding: 0.8rem 1.6rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: var(--plum);
  background: linear-gradient(180deg, #ffe49a, var(--gold));
  box-shadow: 0 0 0 1px rgba(255, 215, 106, 0.6), 0 12px 28px rgba(255, 190, 90, 0.35);
  transition: transform 0.15s var(--ease-soft), box-shadow 0.2s var(--ease-soft);
  touch-action: manipulation;
}
.hg-btn:hover { transform: translateY(-2px); }
.hg-btn:active { transform: scale(0.97); }
.hg-btn:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }

.hg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 420px) {
  .hg-hud { grid-template-areas: "title score" "lights lights" "time time"; }
  .hg-time { flex-direction: row; align-items: center; justify-content: flex-start; gap: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .hg, .hg-hud, .hg-card { transition: opacity 0.2s linear; transform: none; }
  .hg-card, .hg-card.is-on { transform: translate(-50%, -50%); }
  .hg-light.is-lit, .hg-basket.is-catch .hg-body { animation: none; }
  .hg-spark { display: none; }
}
