:root {
  --ink: #4a3b5c;
  --white: #fffdf7;
  --pink: #ff9ec4;
  --yellow: #ffd35c;
  --mint: #8fe3c0;
  --lilac: #c5a8f0;
  --good: #6fd45e;
  --wood: #d9a05b;
  --wood-dark: #b47a3c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", "Comic Sans MS", sans-serif;
  color: var(--ink);
  background: #fdf3dd;
  user-select: none;
  -webkit-user-select: none;
}

#webcam {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: url("../shared/backgrounds/memory.png") center bottom / cover no-repeat;
}

#app { position: relative; z-index: 2; height: 100%; display: flex; flex-direction: column; }

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vh;
  padding: 24px;
  text-align: center;
}
.screen.active { display: flex; }

.game-title {
  font-family: "Titan One", "Fredoka", sans-serif;
  font-size: clamp(2.4rem, 7vw, 4.6rem);
  line-height: 1.05;
  margin: 0;
  color: var(--white);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 6px 0 rgba(74, 59, 92, 0.25);
  transform: rotate(-2deg);
}

.subtitle {
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  font-weight: 600;
  margin: 0;
  background: rgba(255, 253, 247, 0.85);
  padding: 8px 22px;
  border-radius: 999px;
}

.camera-status {
  font-size: 1.05rem;
  font-weight: 600;
  min-height: 1.5em;
  background: rgba(255, 253, 247, 0.75);
  padding: 6px 18px;
  border-radius: 999px;
}

.band-buttons { display: flex; flex-wrap: wrap; gap: clamp(18px, 4vw, 48px); justify-content: center; }

.badge-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  color: var(--white);
  width: clamp(110px, 15vw, 160px);
  height: clamp(110px, 15vw, 160px);
  border-radius: 50%;
  border: 6px dashed var(--white);
  background: radial-gradient(circle at 35% 30%, var(--wood), var(--wood-dark));
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.15);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  line-height: 1.2;
}
.badge-btn:hover, .badge-btn.hovered { transform: scale(1.12) rotate(-4deg); }

.hud { display: flex; justify-content: flex-start; gap: 18px; align-items: center; width: 100%; padding: 16px 22px 0; }

.wood-sign, .wood-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  color: var(--white);
  background: linear-gradient(var(--wood), var(--wood-dark));
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  padding: 8px 20px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}
.wood-btn { cursor: pointer; font-size: clamp(1.3rem, 3vw, 1.9rem); padding: 14px 34px; }
.wood-btn:hover, .wood-btn.hovered { transform: scale(1.08) rotate(-1.5deg); }

.star-trail { font-size: clamp(1.4rem, 3vw, 2rem); letter-spacing: 5px; min-height: 1.2em; }

.corner-links { position: fixed; top: 14px; right: 16px; display: flex; gap: 10px; z-index: 45; }
.corner-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 1.5rem;
  text-decoration: none;
  background: linear-gradient(var(--wood), var(--wood-dark));
  border: 3px solid var(--wood-dark);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.15s;
}
.corner-btn:hover, .corner-btn.hovered { transform: scale(1.12) rotate(-4deg); }

.stage {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  padding: 0 20px 5vh;
}

/* ---------- Cards on the table ---------- */
.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-end;
  gap: clamp(10px, 2vw, 22px);
  max-width: 900px;
  perspective: 1200px;
}

.card {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  width: clamp(88px, 13vw, 150px);
  height: clamp(110px, 16.5vw, 190px);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  animation: deal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
.card:nth-child(2n) { animation-delay: 0.06s; }
.card:nth-child(3n) { animation-delay: 0.12s; }
.card.flipped, .card.matched { transform: rotateY(180deg); }
.card.matched { pointer-events: none; }
.card.matched .card-front { background: var(--good); border-color: #4caf50; }
.card:hover:not(.flipped):not(.matched), .card.hovered:not(.flipped):not(.matched) {
  transform: translateY(-8px) rotate(-2deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(74, 59, 92, 0.25);
}

.card-back {
  background: repeating-linear-gradient(
    45deg, var(--lilac) 0 16px, #b592e8 16px 32px
  );
  border: 5px solid #fff;
  font-size: clamp(2rem, 4.5vw, 3rem);
}

.card-front {
  background: var(--white);
  border: 5px solid var(--pink);
  transform: rotateY(180deg);
  padding: 8px;
  flex-direction: column;
  gap: 4px;
}
.card-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: #fdf7ec;
}
.card-front .word {
  font-weight: 700;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  overflow-wrap: anywhere;
  line-height: 1.1;
  padding: 4px;
}

@keyframes deal {
  from { transform: translateY(40px) scale(0.5); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.end-stars { font-size: clamp(2.6rem, 8vw, 5rem); letter-spacing: 12px; }

/* Hand cursor */
.cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 78px;
  height: 78px;
  margin: -39px 0 0 -39px;
  pointer-events: none;
  z-index: 50;
  transition: opacity 0.25s;
}
.cursor.hidden { opacity: 0; }
.cursor-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 5px solid var(--pink);
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.cursor-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: rgba(255, 158, 196, 0.6); }
.cursor-paw {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  transition: transform 0.1s;
}
.cursor.pinching .cursor-paw { transform: scale(0.7); }
.cursor.pinching .cursor-ring { border-color: var(--good); }

.hand-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 253, 247, 0.94);
  border-radius: 999px;
  padding: 10px 28px;
  font-size: 1.3rem;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(74, 59, 92, 0.28);
  z-index: 40;
  transition: opacity 0.3s;
}
.hand-hint.hidden { opacity: 0; }

.confetti { position: fixed; width: 13px; height: 13px; border-radius: 3px; pointer-events: none; z-index: 60; }

.hidden { visibility: hidden; }

@media (max-width: 620px) {
  .card { width: 26vw; height: 32vw; }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none !important; transition: none; }
}
