* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow-x: hidden;
}
body {
  min-height: 100vh;
  background-image: url('/images/background.webp');
  background-size: cover;
  background-position: bottom right;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

#scene {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.hidden { display: none !important; }

/* ---------- floating pineapple clouds ---------- */
#pineappleLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: hidden;
}
.pineapple-cloud {
  position: absolute;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
  animation-name: drift;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}
.pineapple-cloud.is-door {
  pointer-events: auto;
  cursor: default;
}
@keyframes drift {
  0%   { transform: translate(0, 0) rotate(0deg); }
  50%  { transform: translate(var(--dx, 12px), var(--dy, 10px)) rotate(var(--dr, 3deg)); }
  100% { transform: translate(calc(var(--dx, 12px) * -0.6), calc(var(--dy, 10px) * 0.8)) rotate(calc(var(--dr, 3deg) * -1)); }
}

/* ---------- ambassador select screen ---------- */
.screen {
  position: relative;
  z-index: 2;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.team-cards {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
}

.team-card {
  position: relative;
  width: 210px;
  aspect-ratio: 5 / 8;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border-radius: 20px;
}
.team-card:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.team-art {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.25));
}

.team-stats {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 60%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
}
.stat-label { color: rgba(90, 60, 20, 0.65); font-weight: 500; }
.stat-value { font-weight: 700; color: #6b3f1d; font-size: 15px; }

.play-icon {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b3f1d;
}
.team-card:hover .play-icon { background: rgba(255,255,255,0.8); }

/* rank-based idle animation */
.rank-1 { animation: shake 4s ease-in-out infinite; }
.rank-2 { animation: bob 2.6s ease-in-out infinite; }
.rank-3 { animation: none; }
@keyframes shake {
  0%, 92%, 100% { transform: rotate(0deg); }
  93% { transform: rotate(-4deg); }
  94% { transform: rotate(4deg); }
  95% { transform: rotate(-3deg); }
  96% { transform: rotate(3deg); }
  97% { transform: rotate(-1.5deg); }
  98% { transform: rotate(0deg); }
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ---------- game board ---------- */
#gameScreen { padding: 12px; }
.card-grid {
  display: grid;
  gap: 14px;
  justify-content: center;
  align-content: center;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  perspective: 600px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.35s;
  transform-style: preserve-3d;
}
.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  overflow: hidden;
}
.card-back {
  background: #e8ddb5;
  border: 3px solid #c9ad72;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back::after {
  content: '';
  width: 44%;
  height: 44%;
  background: #c9ad72;
  border-radius: 50%;
  opacity: 0.5;
}
.card-front {
  transform: rotateY(180deg);
  border: 3px solid #fff;
}
.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card.matched { opacity: 0.55; cursor: default; }

/* ---------- win overlay ---------- */
.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(40, 30, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.win-box {
  background: #fbf3de;
  border-radius: 18px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}
.win-box p {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #6b3f1d;
}

/* ---------- hidden login modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(30, 22, 15, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  position: relative;
  background: #fbf3de;
  border-radius: 16px;
  padding: 28px;
  width: 300px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}
.close-x {
  position: absolute;
  top: 10px;
  right: 14px;
  font-size: 20px;
  color: #8a6a4a;
  text-decoration: none;
}
.modal-box label {
  display: block;
  font-size: 13px;
  color: #6b3f1d;
  margin: 10px 0 4px;
  font-weight: 500;
}
.modal-box input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #d8c48f;
  background: #fffaf0;
  font-size: 14px;
}
.modal-box button {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #c9834a;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.modal-box button:hover { background: #b8733d; }
.error { color: #a33; font-size: 13px; margin-top: 8px; }

@media (max-width: 640px) {
  .team-cards { gap: 14px; }
  .team-card { width: 30vw; min-width: 110px; }
  .stat { font-size: 11px; }
  .stat-value { font-size: 12px; }
}
