:root {
  --ink: #4a3b5c;
  --white: #fffdf7;
  --pink: #ff9ec4;
  --yellow: #ffd35c;
  --mint: #8fe3c0;
  --lilac: #c5a8f0;
  --good: #6fd45e;
  --bad: #ff8a8a;
  --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: linear-gradient(#aee4f5, #d8f2fb 70%);
  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/train.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;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  width: 100%;
  padding: 0 16px 3vh;
}

/* ---------- Choice crates ---------- */
.choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(16px, 4vw, 44px);
}

.crate {
  border: none;
  cursor: pointer;
  width: clamp(96px, 14vw, 150px);
  height: clamp(96px, 14vw, 150px);
  border-radius: 18px;
  background: linear-gradient(var(--wood), var(--wood-dark));
  border: 4px solid var(--wood-dark);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}
.crate:nth-child(2) { animation-delay: 0.08s; }
.crate:nth-child(3) { animation-delay: 0.16s; }
.crate:hover, .crate.hovered { transform: scale(1.14) rotate(-3deg); }
.crate.wrong { background: var(--bad); opacity: 0.4; pointer-events: none; animation: shake 0.4s; }
.crate.correct { background: var(--good); transform: scale(1.15); }

/* ---------- The train ---------- */
.train {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  width: 100%;
  overflow: hidden;
  padding-bottom: 1vh;
}
.train.depart { animation: depart 1.6s ease-in forwards; }
@keyframes depart {
  to { transform: translateX(-120vw); }
}

.engine img {
  display: block;
  width: clamp(110px, 16vw, 200px);
  height: auto;
}
.engine-emoji { font-size: clamp(4rem, 10vw, 7rem); line-height: 1; }

.wagons { display: flex; align-items: flex-end; gap: 6px; }

.wagon {
  position: relative;
  width: clamp(76px, 11vw, 130px);
  padding: 8px 8px 14px;
  background: var(--lilac);
  border: 4px solid #a284d4;
  border-radius: 12px 12px 8px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(76px, 11vw, 130px);
}
.wagon::before, .wagon::after {
  content: "";
  position: absolute;
  bottom: -14px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid #8f84a3;
}
.wagon::before { left: 12%; }
.wagon::after { right: 12%; }

.wagon.gap {
  background: rgba(255, 253, 247, 0.65);
  border-style: dashed;
  border-color: var(--wood-dark);
}
.wagon.gap .piece-slot {
  font-family: "Titan One", "Fredoka", sans-serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  color: var(--wood-dark);
}
.wagon.filled { background: var(--mint); border-color: #64c39a; animation: bounce 0.5s ease; }

/* ---------- Pattern pieces (shared by wagons and crates) ---------- */
.piece { display: flex; align-items: center; justify-content: center; }
.piece img { width: clamp(52px, 8vw, 95px); height: clamp(52px, 8vw, 95px); object-fit: contain; }
.piece .dot { width: clamp(44px, 7vw, 80px); height: clamp(44px, 7vw, 80px); border-radius: 50%; border: 4px solid rgba(0, 0, 0, 0.15); }
.piece .glyph { font-size: clamp(2.4rem, 6vw, 4.2rem); line-height: 1; }
.piece .num {
  font-family: "Titan One", "Fredoka", sans-serif;
  font-size: clamp(2rem, 5vw, 3.6rem);
  color: var(--ink);
  background: var(--white);
  border-radius: 12px;
  padding: 2px 14px;
}

@keyframes pop-in {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes bounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

.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) {
  .wagon { width: 17vw; min-height: 17vw; }
  .crate { width: 24vw; height: 24vw; }
  .engine img { width: 24vw; }
}

@media (prefers-reduced-motion: reduce) {
  .crate, .wagon.filled, .train.depart { animation: none !important; }
}
