/* ==========================================================
   CATCH MY HEART (game.js). Everything here is prefixed hg-.
   ========================================================== */

.hg {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

/* gilded frame around the canvas */
.hg-shell {
  position: relative;
  padding: 5px;
  border-radius: 30px;
  background: linear-gradient(140deg, #f6e6b6 0%, var(--gold, #c9a24b) 24%, #8c6a22 50%, var(--gold-soft, #e6cf96) 74%, #a88330 100%);
  box-shadow:
    0 28px 54px rgba(43, 7, 16, 0.32),
    0 6px 14px rgba(43, 7, 16, 0.18),
    inset 0 0 0 1px rgba(255, 245, 210, 0.55);
}

.hg-frame {
  position: relative;
  height: 68vh;
  height: min(68vh, 560px);
  height: min(68svh, 560px);
  min-height: 380px;
  border-radius: 25px;
  overflow: hidden;
  isolation: isolate;
  background: #19030a;
  box-shadow: inset 0 0 0 1px rgba(43, 7, 16, 0.6);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* thin inner gold hairline */
.hg-frame::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 6px;
  border-radius: 20px;
  border: 1px solid rgba(230, 207, 150, 0.22);
  pointer-events: none;
}

.hg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.hg-frame[data-state="playing"] .hg-canvas {
  cursor: none;
}

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

/* ---------- HUD ---------- */
.hg-hud {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hg-hud__right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hg-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--paper, #fffaf6);
  background: linear-gradient(180deg, rgba(92, 16, 34, 0.86), rgba(43, 7, 16, 0.86));
  box-shadow:
    inset 0 0 0 1px rgba(230, 207, 150, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 6px 14px rgba(0, 0, 0, 0.28);
}

.hg-score {
  overflow: hidden;
  padding: 0 13px 2px 10px;
  font-family: var(--font-display, Georgia, serif);
  line-height: 1;
}
.hg-score__icon {
  width: 15px;
  height: 15px;
  flex: none;
  fill: var(--gold-soft, #e6cf96);
}
.hg-score__num {
  display: inline-block;
  min-width: 1.1ch;
  font-weight: 700;
  font-size: 1.12rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.hg-score__of {
  margin-left: -3px;
  font-style: italic;
  font-size: 0.86rem;
  color: var(--gold-soft, #e6cf96);
  opacity: 0.9;
}
.hg-score__bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 5px;
  height: 2px;
  border-radius: 2px;
  background: rgba(230, 207, 150, 0.18);
  overflow: hidden;
}
.hg-score__bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-soft, #e6cf96), var(--gold, #c9a24b));
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.35s var(--ease, ease);
}

.hg-lives {
  gap: 4px;
  padding: 0 11px;
}
.hg-life {
  width: 17px;
  height: 17px;
  flex: none;
  fill: #f07a94;
  stroke: rgba(255, 228, 235, 0.5);
  stroke-width: 0.8;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
  transition: fill 0.3s var(--ease, ease), opacity 0.3s;
}
.hg-life.is-lost {
  fill: rgba(251, 243, 238, 0.06);
  stroke: rgba(251, 243, 238, 0.42);
  stroke-width: 1.5;
  filter: none;
}
.hg-lives__count {
  font-family: var(--font-display, Georgia, serif);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
}

.hg-pausebtn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: -6px -6px -6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
.hg-pausebtn__face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(92, 16, 34, 0.86), rgba(43, 7, 16, 0.86));
  box-shadow:
    inset 0 0 0 1px rgba(230, 207, 150, 0.45),
    0 6px 14px rgba(0, 0, 0, 0.28);
  transition: transform 0.2s var(--ease-bounce, ease);
}
.hg-pausebtn__face i {
  display: block;
  width: 3.5px;
  height: 13px;
  border-radius: 2px;
  background: var(--gold-soft, #e6cf96);
}
.hg-pausebtn:active .hg-pausebtn__face {
  transform: scale(0.9);
}
.hg-pausebtn:focus-visible {
  outline: none;
}
.hg-pausebtn:focus-visible .hg-pausebtn__face {
  outline: 3px solid var(--gold, #c9a24b);
  outline-offset: 2px;
}

/* ---------- overlays ---------- */
.hg-ov {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse 85% 70% at 50% 50%, rgba(25, 3, 10, 0.18), rgba(25, 3, 10, 0.6));
  opacity: 0;
  transition: opacity 0.35s var(--ease, ease);
}
.hg-ov.is-in {
  opacity: 1;
}

.hg-card {
  position: relative;
  width: 100%;
  max-width: 318px;
  padding: 24px 20px 20px;
  border-radius: 22px;
  text-align: center;
  color: var(--text, #2b0710);
  background:
    radial-gradient(ellipse 90% 55% at 50% 0%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse at center, transparent 60%, rgba(201, 162, 75, 0.12) 100%),
    linear-gradient(170deg, var(--paper, #fffaf6), #fbede8);
  box-shadow:
    0 26px 50px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(201, 162, 75, 0.6);
  transform: translateY(16px) scale(0.94);
  transition: transform 0.55s var(--ease-bounce, ease);
}
.hg-card::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 17px;
  border: 1px solid rgba(201, 162, 75, 0.38);
  pointer-events: none;
}
.hg-ov.is-in .hg-card {
  transform: none;
}

.hg-card__title {
  position: relative;
  margin: 0;
  font-family: var(--font-display, Georgia, serif);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.55rem, 7vw, 1.9rem);
  line-height: 1.12;
  color: var(--burgundy, #800020);
  text-wrap: balance;
}
.hg-card__text {
  position: relative;
  margin: 8px auto 0;
  max-width: 26ch;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-soft, #6b3a46);
  white-space: pre-line;
  text-wrap: pretty;
}

.hg-card--win .hg-btn {
  margin-top: 20px;
}

.hg-card__how {
  position: relative;
  margin: 12px 0 16px;
  font-family: var(--font-hand, cursive);
  font-weight: 700;
  font-size: 1.42rem;
  line-height: 1.15;
  color: var(--wine, #a3243b);
  rotate: -1.5deg;
  text-wrap: balance;
}

.hg-best {
  position: relative;
  margin: 14px 0 0;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft, #6b3a46);
}
.hg-best b {
  font-family: var(--font-display, Georgia, serif);
  font-style: italic;
  font-size: 1rem;
  letter-spacing: 0;
  color: var(--burgundy, #800020);
}

/* legend: heart +1, troll +3, gold +5 */
.hg-legend {
  position: relative;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.hg-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 38px;
  padding: 0 12px 0 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff, var(--blush-soft, #f8e1e6));
  box-shadow: inset 0 0 0 1px rgba(201, 162, 75, 0.5), 0 3px 8px rgba(74, 14, 28, 0.1);
}
.hg-legend__pts {
  font-family: var(--font-display, Georgia, serif);
  font-style: italic;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  color: var(--burgundy, #800020);
}
.hg-ico {
  width: 21px;
  height: 21px;
  flex: none;
}
.hg-ico--rose {
  fill: var(--rose, #c94f6d);
}
.hg-ico--troll {
  display: inline-grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  filter: drop-shadow(0 0 3px rgba(201, 162, 75, 0.7));
}

/* buttons */
.hg-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 156px;
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  font-family: var(--font-body, sans-serif);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  color: var(--paper, #fffaf6);
  background: linear-gradient(180deg, #b52a4c 0%, var(--burgundy, #800020) 55%, #5c0418 100%);
  box-shadow:
    0 10px 22px rgba(128, 0, 32, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 0 0 1.5px rgba(230, 207, 150, 0.7);
  transition: transform 0.22s var(--ease-bounce, ease), filter 0.2s, box-shadow 0.2s;
}
.hg-btn:active {
  transform: scale(0.95);
}
.hg-btn:focus-visible {
  outline: 3px solid var(--gold, #c9a24b);
  outline-offset: 3px;
}
@media (hover: hover) {
  .hg-btn:hover {
    filter: brightness(1.08);
    box-shadow:
      0 14px 28px rgba(128, 0, 32, 0.42),
      inset 0 1px 0 rgba(255, 255, 255, 0.3),
      inset 0 0 0 1.5px rgba(230, 207, 150, 0.85);
  }
}
.hg-btn--big {
  min-width: 184px;
  min-height: 60px;
  font-size: 1.22rem;
  letter-spacing: 0.08em;
}
.hg-btn--start {
  animation: hg-glow 2.4s ease-in-out infinite;
}
.hg-btn__icon {
  width: 19px;
  height: 19px;
  flex: none;
  fill: var(--gold-soft, #e6cf96);
}
.hg-btn__icon--retry {
  width: 18px;
  height: 18px;
  fill: none;
  color: var(--gold-soft, #e6cf96);
}

@keyframes hg-glow {
  0%, 100% {
    box-shadow:
      0 10px 22px rgba(128, 0, 32, 0.36),
      0 0 0 0 rgba(201, 79, 109, 0.45),
      inset 0 1px 0 rgba(255, 255, 255, 0.28),
      inset 0 0 0 1.5px rgba(230, 207, 150, 0.7);
  }
  50% {
    box-shadow:
      0 10px 22px rgba(128, 0, 32, 0.36),
      0 0 0 10px rgba(201, 79, 109, 0),
      inset 0 1px 0 rgba(255, 255, 255, 0.28),
      inset 0 0 0 1.5px rgba(230, 207, 150, 0.7);
  }
}

/* stats on the lose card */
.hg-stats {
  position: relative;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 18px;
}
.hg-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px 6px;
  border-radius: 999px;
  background: rgba(242, 196, 206, 0.45);
  box-shadow: inset 0 0 0 1px rgba(201, 162, 75, 0.4);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-soft, #6b3a46);
}
.hg-stat__val {
  font-family: var(--font-display, Georgia, serif);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: 0;
  color: var(--burgundy, #800020);
}
.hg-stat--new {
  align-items: center;
  color: var(--burgundy-ink, #2b0710);
  font-weight: 700;
  background: linear-gradient(135deg, #f6e6b6, var(--gold, #c9a24b));
  box-shadow: 0 3px 8px rgba(140, 106, 34, 0.3);
}

/* broken heart on the lose card */
.hg-broken {
  position: relative;
  width: 62px;
  height: 62px;
  margin: -4px auto 8px;
  filter: drop-shadow(0 8px 10px rgba(74, 14, 28, 0.28));
}
.hg-broken__svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.hg-ov.is-in .hg-broken__l {
  animation: hg-crack-l 0.7s var(--ease, ease) 0.15s both;
}
.hg-ov.is-in .hg-broken__r {
  animation: hg-crack-r 0.7s var(--ease, ease) 0.15s both;
}
@keyframes hg-crack-l {
  from { transform: translate(0, 0) rotate(0deg); }
}
@keyframes hg-crack-r {
  from { transform: translate(0, 0) rotate(0deg); }
}

/* gold medal + heart burst on the win card */
.hg-medal {
  position: relative;
  width: 78px;
  height: 78px;
  margin: -6px auto 10px;
}
.hg-medal__svg {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 10px 14px rgba(140, 106, 34, 0.35));
  animation: hg-beat 2.2s ease-in-out infinite;
  transform-origin: 50% 55%;
}
@keyframes hg-beat {
  0%, 60%, 100% { transform: scale(1); }
  12% { transform: scale(1.09); }
  24% { transform: scale(0.98); }
  36% { transform: scale(1.05); }
}

.hg-burst {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
}
.hg-burst__h {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 18px;
  height: 18px;
  opacity: 0;
}
.hg-burst__h svg {
  width: 100%;
  height: 100%;
}
.hg-burst.is-go .hg-burst__h {
  animation: hg-burst 1.25s cubic-bezier(0.15, 0.75, 0.3, 1) var(--delay, 0ms) both;
}
@keyframes hg-burst {
  0% {
    opacity: 0;
    transform: translate(0, 0) rotate(0deg) scale(0.2);
  }
  15% {
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--r, 0deg)) scale(var(--s, 1));
  }
}

/* pause overlay: one big button */
.hg-ov--pause {
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  font: inherit;
  color: var(--paper, #fffaf6);
  touch-action: manipulation;
  background:
    radial-gradient(ellipse 80% 60% at 50% 50%, rgba(25, 3, 10, 0.4), rgba(25, 3, 10, 0.72));
}
.hg-ov--pause:focus-visible {
  outline: 3px solid var(--gold, #c9a24b);
  outline-offset: -8px;
}
.hg-pausecard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transform: scale(0.94);
  transition: transform 0.45s var(--ease-bounce, ease);
}
.hg-ov--pause.is-in .hg-pausecard {
  transform: none;
}
.hg-pausecard__ring {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: linear-gradient(180deg, #b52a4c, var(--burgundy, #800020) 60%, #5c0418);
  box-shadow:
    0 0 0 4px rgba(230, 207, 150, 0.85),
    0 0 0 9px rgba(230, 207, 150, 0.18),
    0 14px 30px rgba(0, 0, 0, 0.45);
  animation: hg-breathe 2.4s ease-in-out infinite;
}
.hg-pausecard__ring svg {
  width: 30px;
  height: 30px;
  margin-left: 4px;
  fill: var(--paper, #fffaf6);
}
.hg-pausecard__title {
  font-family: var(--font-display, Georgia, serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.85rem;
  line-height: 1.1;
}
.hg-pausecard__hint {
  font-family: var(--font-hand, cursive);
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1.1;
  color: var(--blush, #f2c4ce);
}
@keyframes hg-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* small phones */
@media (max-width: 359px) {
  .hg-shell {
    padding: 4px;
    border-radius: 26px;
  }
  .hg-frame {
    border-radius: 22px;
  }
  .hg-hud {
    top: 10px;
    left: 10px;
    right: 10px;
  }
  .hg-pill {
    height: 34px;
    padding: 0 10px;
  }
  .hg-life {
    width: 15px;
    height: 15px;
  }
  .hg-card {
    padding: 22px 16px 18px;
  }
  .hg-legend__item {
    height: 36px;
    padding: 0 10px 0 8px;
  }
  .hg-btn--big {
    min-width: 168px;
    min-height: 56px;
  }
}

/* short screens (phones sideways) */
@media (max-height: 460px) {
  .hg-card {
    padding: 16px 16px 14px;
  }
  .hg-medal,
  .hg-broken {
    width: 52px;
    height: 52px;
    margin-bottom: 4px;
  }
  .hg-card__how {
    margin: 8px 0 10px;
  }
  .hg-stats {
    margin: 10px 0 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hg-btn--start,
  .hg-medal__svg,
  .hg-pausecard__ring,
  .hg-burst.is-go .hg-burst__h,
  .hg-ov.is-in .hg-broken__l,
  .hg-ov.is-in .hg-broken__r {
    animation: none !important;
  }
  .hg-card,
  .hg-pausecard {
    transform: none;
    transition: none;
  }
  .hg-ov {
    transition-duration: 0.01s;
  }
  .hg-score__bar i {
    transition: none;
  }
}
