/* ============================ Slam! — styles ============================ */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", system-ui, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(130% 90% at 50% 0%, #efe1ff 0%, #d9c2ff 45%, #ffd9ec 100%);
  transition: background 0.5s ease;
}

/* The whole table rattles when a card slams down. */
#game.shake { animation: tableShake 0.35s ease; }
@keyframes tableShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-7px, 4px) rotate(-0.6deg); }
  40% { transform: translate(6px, -5px) rotate(0.5deg); }
  60% { transform: translate(-4px, 3px); }
  80% { transform: translate(3px, -2px); }
}

/* ------------------------------- HUD -------------------------------- */

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: clamp(8px, 2.4vw, 22px);
  padding: clamp(6px, 2vw, 14px) clamp(8px, 2vw, 16px);
  flex-wrap: wrap;
}

.hud-item { flex: 0 0 auto; text-align: center; }

.stat-label {
  font-size: clamp(14px, 3.4vw, 20px);
  font-weight: 700;
  color: #4a3a6a;
  white-space: nowrap;
}

.stat-label b { color: #8a2fbf; font-size: 1.15em; }

#score-num.bump { display: inline-block; animation: bump 0.3s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.6); color: #ff9500; }
  100% { transform: scale(1); }
}

#say-btn {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: clamp(20px, 5vw, 30px);
  line-height: 1;
  background: rgba(255, 255, 255, 0.9);
  border: 3px solid #d3a8f0;
  border-radius: 50%;
  width: clamp(42px, 11vw, 56px);
  height: clamp(42px, 11vw, 56px);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(140, 80, 190, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  touch-action: manipulation;
}

#say-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(140, 80, 190, 0.3);
}

/* ------------------------------ Stage -------------------------------- */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(70px, 20vw, 150px) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "player word"
    "cards  cards";
  align-items: center;
  padding: clamp(4px, 1.5vw, 12px) clamp(8px, 2.5vw, 20px);
  gap: clamp(4px, 1.5vw, 12px);
}

/* --- your player --- */

#player-zone {
  grid-area: player;
  text-align: center;
  align-self: center;
}

#player {
  font-size: clamp(48px, 14vw, 100px);
  line-height: 1;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25));
  animation: bob 2.2s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

#player.slamming { animation: playerSlam 0.55s ease; }
@keyframes playerSlam {
  0% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(-34px) rotate(-14deg) scale(1.08); }
  70% { transform: translateY(8px) rotate(9deg) scale(1.12); }
  100% { transform: translateY(0) rotate(0); }
}

#player.cheer { animation: playerCheer 0.85s ease; }
@keyframes playerCheer {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-26px) rotate(-12deg); }
  50% { transform: translateY(0) rotate(0); }
  75% { transform: translateY(-20px) rotate(12deg); }
}

#player.sad {
  animation: none;
  transform: rotate(14deg) translateY(10px);
  filter: grayscale(0.6) drop-shadow(0 4px 4px rgba(0, 0, 0, 0.25));
  transition: transform 0.4s ease, filter 0.4s ease;
}

#player-name {
  font-size: clamp(13px, 3vw, 18px);
  font-weight: 800;
  color: #4a3a6a;
  margin-top: 2px;
}

/* --- the word with its missing-letter slots --- */

#word-zone {
  grid-area: word;
  text-align: center;
  min-width: 0;
}

#word-hint {
  font-size: clamp(13px, 3.2vw, 18px);
  font-weight: 700;
  color: #6a4a8a;
  margin-bottom: clamp(6px, 1.5vw, 12px);
}

#word-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(5px, 1.4vw, 12px);
}

.tile {
  width: clamp(42px, 11vw, 84px);
  height: clamp(52px, 13vw, 100px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(28px, 7.5vw, 58px);
  font-weight: 800;
  color: #4a3a6a;
  background: #fff;
  border: 3px solid #d3a8f0;
  border-radius: 14px;
  box-shadow: 0 5px 0 rgba(140, 80, 190, 0.25), 0 8px 14px rgba(0, 0, 0, 0.12);
  animation: tileIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes tileIn {
  from { transform: translateY(-24px) scale(0.4); opacity: 0; }
}

/* An empty slot waiting for its letter. */
.tile.blank {
  background: rgba(255, 255, 255, 0.35);
  border-style: dashed;
  border-color: #b07ae0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* The blank you're solving right now glows. */
.tile.blank.current {
  border-color: #ff9500;
  background: #fff6de;
  animation: glowPulse 1s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 170, 40, 0.55), inset 0 2px 8px rgba(0, 0, 0, 0.08); }
  50% { box-shadow: 0 0 0 10px rgba(255, 170, 40, 0), inset 0 2px 8px rgba(0, 0, 0, 0.08); }
}

/* A slot that just got its letter slammed in. */
.tile.filled {
  border-style: solid;
  border-color: #63c76e;
  background: #eaffe9;
  color: #2f9d4e;
  animation: fillPop 0.35s cubic-bezier(0.34, 1.8, 0.64, 1);
}

@keyframes fillPop {
  0% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* --- the letter cards --- */

#cards-zone {
  grid-area: cards;
  padding-bottom: clamp(8px, 2.4vw, 18px);
}

#cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(8px, 2.2vw, 18px);
  perspective: 900px;
}

.card {
  width: clamp(58px, 15vw, 96px);
  height: clamp(72px, 19vw, 120px);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  animation: dealIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  touch-action: manipulation;
}

@keyframes dealIn {
  from { transform: translateY(70px) scale(0.3) rotate(10deg); opacity: 0; }
}

.card:disabled { cursor: default; }

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped .card-inner { transform: rotateY(180deg); }

.card:not(:disabled):active .card-inner { transform: rotateY(180deg) scale(0.94); }

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Face-down: a starry card back. */
.face-front {
  font-size: clamp(24px, 6vw, 40px);
  color: #fff;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.25) 0 12%, transparent 13%),
    radial-gradient(circle at 70% 70%, rgba(255, 255, 255, 0.2) 0 10%, transparent 11%),
    linear-gradient(150deg, #9a5fc6, #6a3f9a);
  border: 3px solid #55307d;
  box-shadow: 0 5px 0 #4a2a6d, 0 8px 14px rgba(0, 0, 0, 0.2);
}

/* Face-up: the letter. */
.face-back {
  transform: rotateY(180deg);
  font-size: clamp(32px, 9vw, 62px);
  font-weight: 800;
  color: #4a3a6a;
  background: linear-gradient(180deg, #fff, #f3e8ff);
  border: 3px solid #b07ae0;
  box-shadow: 0 5px 0 rgba(140, 80, 190, 0.35), 0 8px 14px rgba(0, 0, 0, 0.18);
}

/* --- the flying card mid-SLAM --- */

.fly-card {
  position: fixed;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: clamp(32px, 9vw, 62px);
  font-weight: 800;
  color: #4a3a6a;
  background: linear-gradient(180deg, #fff, #f3e8ff);
  border: 3px solid #b07ae0;
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  will-change: transform;
}

/* The wrong card shaking its head "no". */
.fly-card.no-no { animation: noNo 0.55s ease; }
@keyframes noNo {
  0%, 100% { rotate: 0deg; }
  20% { rotate: -14deg; }
  40% { rotate: 12deg; }
  60% { rotate: -10deg; }
  80% { rotate: 8deg; }
}

/* Comic-book "SLAM!" burst. */
.slam-pop {
  position: fixed;
  z-index: 80;
  transform: translate(-50%, -100%) rotate(-8deg);
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: clamp(30px, 9vw, 60px);
  font-weight: 800;
  color: #ff9500;
  -webkit-text-stroke: 2px #7d3a00;
  text-shadow: 0 4px 0 rgba(125, 58, 0, 0.35);
  pointer-events: none;
  animation: slamPop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes slamPop {
  0% { transform: translate(-50%, -100%) rotate(-8deg) scale(0.2); opacity: 0; }
  30% { transform: translate(-50%, -110%) rotate(-8deg) scale(1.25); opacity: 1; }
  80% { transform: translate(-50%, -115%) rotate(-8deg) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -130%) rotate(-8deg) scale(1); opacity: 0; }
}

/* The wrong letter's "Nu-uh!" speech bubble. */
.nuh-bubble {
  position: fixed;
  z-index: 80;
  transform: translate(-50%, -100%);
  font-family: "Baloo 2", system-ui, sans-serif;
  font-size: clamp(18px, 4.5vw, 28px);
  font-weight: 800;
  color: #e10046;
  background: #fff;
  border: 3px solid #e10046;
  border-radius: 16px 16px 16px 4px;
  padding: 6px 14px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  white-space: nowrap;
  animation: bubbleIn 1.05s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes bubbleIn {
  0% { transform: translate(-50%, -80%) scale(0.2); opacity: 0; }
  20% { transform: translate(-50%, -100%) scale(1.1); opacity: 1; }
  85% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -110%) scale(0.9); opacity: 0; }
}

/* --------------------------- FX canvas ------------------------------ */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

/* ---------------------------- Overlays ------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(50, 30, 70, 0.45);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}

.overlay.show { display: flex; }
.overlay.lose { background: rgba(60, 25, 45, 0.5); }
.overlay.pick { background: rgba(50, 30, 70, 0.55); }

.card-box {
  background: #fff;
  border-radius: 28px;
  border: 6px solid #d3a8f0;
  box-shadow: 0 16px 0 rgba(140, 80, 190, 0.25), 0 24px 40px rgba(0, 0, 0, 0.3);
  padding: clamp(20px, 5vw, 40px);
  max-width: 460px;
  width: 100%;
  text-align: center;
  animation: cardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardIn {
  from { transform: scale(0.6) translateY(30px); opacity: 0; }
}

.card-emoji {
  font-size: clamp(46px, 12vw, 72px);
  line-height: 1;
  margin-bottom: 6px;
}

.card-box h1 {
  margin: 6px 0 12px;
  font-size: clamp(30px, 8vw, 48px);
  font-weight: 800;
  color: #8a2fbf;
  letter-spacing: 1px;
}

.overlay.lose .card-box h1 { color: #e10046; }

.card-box p {
  margin: 8px 0;
  font-size: clamp(15px, 3.6vw, 19px);
  font-weight: 500;
  color: #4a3a5a;
}

.card-box p.small { font-size: clamp(13px, 3vw, 16px); color: #8a7a9a; }

.card-box .new-best {
  font-weight: 800;
  color: #ff9500;
  font-size: clamp(17px, 4.2vw, 22px);
}

.lose-word { letter-spacing: 2px; }
.lose-word .missed {
  color: #e10046;
  text-decoration: underline wavy #e10046;
}

.big-btn {
  margin-top: 18px;
  font-family: inherit;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #b06ae0, #8a2fbf);
  border: none;
  border-radius: 99px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 6px 0 #6a2393, 0 10px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  touch-action: manipulation;
}

.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #6a2393, 0 4px 10px rgba(0, 0, 0, 0.25);
}

.change-btn {
  display: block;
  margin: 14px auto 0;
  font-family: inherit;
  font-size: clamp(14px, 3.4vw, 18px);
  font-weight: 700;
  color: #6a4a8a;
  background: #f3e8ff;
  border: 3px solid #d3a8f0;
  border-radius: 99px;
  padding: 8px 22px;
  cursor: pointer;
  touch-action: manipulation;
}

.change-btn:active { transform: translateY(2px); }

/* --------------------- Pick-your-player screen ---------------------- */

.pick-wrap {
  text-align: center;
  max-width: 640px;
  width: 100%;
}

.pick-wrap h1 {
  margin: 0 0 6px;
  font-size: clamp(26px, 7vw, 44px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 rgba(90, 40, 130, 0.6);
}

.pick-wrap > p {
  margin: 0 0 18px;
  font-size: clamp(15px, 3.8vw, 20px);
  font-weight: 700;
  color: #f0dcff;
}

.pick-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(10px, 3vw, 22px);
  overflow: hidden;
  padding: 10px;
}

/* Each player runs out from the left, then bounces in place. */
.pick-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  background: #fff;
  border: 4px solid #d3a8f0;
  border-radius: 20px;
  padding: clamp(10px, 2.6vw, 18px) clamp(12px, 3vw, 22px);
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(140, 80, 190, 0.3), 0 10px 18px rgba(0, 0, 0, 0.2);
  animation: runOut 0.6s cubic-bezier(0.34, 1.3, 0.64, 1) both;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  touch-action: manipulation;
}

@keyframes runOut {
  from { transform: translateX(-120vw) rotate(-20deg); }
}

.pick-player:hover, .pick-player:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 8px 0 rgba(140, 80, 190, 0.35), 0 14px 22px rgba(0, 0, 0, 0.25);
}

.pick-player:active { transform: scale(0.95); }

.pp-emoji {
  font-size: clamp(38px, 10vw, 64px);
  line-height: 1;
  animation: bob 1.6s ease-in-out infinite;
}

.pp-name {
  font-size: clamp(13px, 3.2vw, 17px);
  font-weight: 800;
  color: #6a4a8a;
}
