* { 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;
}

/* Positioned absolutely (not a flex sibling) so it doesn't disturb the
   centered layout .screen already uses for other screens like the game
   board — anchored to the bottom of the ambassador screen specifically,
   below wherever the team cards land. */
.help-icon {
  position: absolute;
  bottom: -90px; /* manually tuned by hand-testing on the real page — don't reset this without checking first */
  left: 50%;
  transform: translateX(-50%);
  width: 64px;
  height: 64px;
  cursor: pointer;
  z-index: 3;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
  animation: help-bob 3s ease-in-out infinite;
}
@keyframes help-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.help-modal.hidden { display: none; }
.help-modal-box {
  position: relative;
  background: #fffdf5;
  border: 5px solid #3a5cff;
  border-radius: 22px;
  padding: 28px 32px;
  max-width: 840px;
  width: 90vw;
  text-align: left;
}
.help-modal-box h2 {
  margin: 0 0 12px;
  text-align: center;
}
.help-modal-box p {
  margin: 0 0 12px;
  line-height: 1.5;
  font-size: 0.95em;
}
.help-modal-box p:last-child { margin-bottom: 0; }
.help-modal-close {
  position: absolute;
  top: 10px;
  right: 16px;
  font-size: 1.4em;
  text-decoration: none;
  color: inherit;
}

.help-team-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 8px;
}
.help-team-column {
  background: rgba(58, 92, 255, 0.06);
  border: 1px solid rgba(58, 92, 255, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
}
.help-team-name {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 0.95em;
}
.help-team-column ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.88em;
  line-height: 1.6;
}
@media (max-width: 640px) {
  .help-team-columns { grid-template-columns: 1fr; }
}

.team-card {
  position: relative;
  width: 210px;
  border-width: 5px;
  border-style: solid;
  border-radius: 22px;
  background: #ffefc0;
  padding: 16px 14px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
.team-card:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.team-card-duckie { border-color: #FF0057; }
.team-card-rocky { border-color: #CD8030; }
.team-card-froggleton { border-color: #AC4E08; }

.team-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-align: center;
}
.team-card-duckie .team-card-title { color: #FF0057; }
.team-card-rocky .team-card-title { color: #CD5530; }
.team-card-froggleton .team-card-title { color: #85891B; }

.team-logo {
  width: 110px;
  height: 110px;
  object-fit: contain;
}

.team-stats {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat-label {
  color: #4a3423;
  opacity: 0.7;
  font-weight: 500;
  font-size: 12px;
}
.stat-value { font-weight: 700; color: #4a3423; font-size: 15px; }

.fastest-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin-top: 2px;
}
.fastest-list span {
  background: rgba(74,52,35,0.1);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 700;
  color: #4a3423;
}

/* rank-based idle animation */
.rank-1 { animation: bob 2.6s ease-in-out infinite; }
.rank-2 { animation: shake 4s 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; padding: 10px 8px 10px; gap: 6px; border-width: 3px; }
  .team-card-title { font-size: 11px; }
  .team-logo { width: 60px; height: 60px; }
  .stat-label { font-size: 10px; }
  .fastest-list span { font-size: 10px; padding: 0 4px; }
  .stat-value { font-size: 12px; }

  /* Pixel-offset positioning (top or bottom) kept failing because .screen
     vertically CENTERS its content — where the card stack actually starts
     depends on both the stack's height and the viewport's height, neither
     of which a fixed offset can reliably predict. Real document flow sidesteps
     the guessing entirely: the icon becomes a genuine flex item alongside
     the cards (not absolutely positioned out of the flow), and `order`
     places it first without touching the HTML itself. */
  #ambassadorScreen {
    flex-direction: column;
    gap: 16px;
  }
  .help-icon {
    position: static;
    order: -1;
    transform: none;
    animation: help-bob-static 3s ease-in-out infinite;
  }
}
@keyframes help-bob-static {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
