/* ---------- Reset & page ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 14px;
}

h1 {
  color: #fff;
  font-size: 2.4rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, .3);
}

.game-info {
  color: rgba(255, 255, 255, .9);
  font-size: 1.05rem;
}

/* ---------- Board ---------- */
.game-container {
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .12);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  height: 100%;
}

/* The panel is the "room" behind the door */
.door-panel {
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  background: linear-gradient(145deg, #c7d2fe, #a5b4fc);
  cursor: pointer;
  user-select: none;
  transition: transform .2s ease, box-shadow .2s ease;
}

.door-panel:focus-visible {
  outline: 3px solid #ffd700;
  outline-offset: 2px;
}

.door-panel:hover:not(.locked) {
  transform: scale(1.04);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

.door-panel.locked { cursor: default; }

/* The emoji hiding behind the door */
.hidden-emoji {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 10vw, 3.75rem);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
}

/* The sliding door overlay */
.door-door {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 10vw, 9rem);
  background: linear-gradient(145deg, #ffd700, #ff8c00);
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
  transition: transform .45s cubic-bezier(.34, 1.3, .64, 1);
  z-index: 5;
}

/* Peek: door slides partly aside to flash the emoji */
.door-panel.peeking .door-door { transform: translateX(-50%); }
.door-panel.peeking .hidden-emoji { opacity: 1; }

/* Fully open: door gone, emoji shown */
.door-panel.open .door-door { transform: translateX(-110%); }
.door-panel.open .hidden-emoji { opacity: 1; transform: scale(1.15); }

/* Outcome styling */
.door-panel.correct { box-shadow: 0 0 0 4px #22c55e, 0 0 26px #22c55e; }
.door-panel.correct .hidden-emoji { animation: pop .5s ease infinite alternate; }

.door-panel.wrong .hidden-emoji { opacity: .58; filter: grayscale(.6); }

/* ---------- Animations ---------- */
@keyframes shuffleMove {
  0%   { transform: translate(0, 0) rotate(0deg); }
  20%  { transform: translate(14px, -10px) rotate(4deg); }
  40%  { transform: translate(-12px, 8px) rotate(-3deg); }
  60%  { transform: translate(10px, 6px) rotate(2deg); }
  80%  { transform: translate(-8px, -12px) rotate(-4deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.door-panel.shuffling { animation: shuffleMove .34s ease-in-out infinite; }

@keyframes pop {
  from { transform: scale(1); }
  to   { transform: scale(1.4); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}

.door-panel.shake { animation: shake .4s ease; }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.mode-buttons { display: flex; gap: 12px; }

.mode-btn {
  padding: 13px 26px;
  border: none;
  border-radius: 999px;
  font-size: .98rem;
  font-weight: 700;
  background: rgba(255, 255, 255, .92);
  color: #333;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}

.mode-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}

.mode-btn.active { background: #ffd700; }

.mode-btn:disabled { opacity: .55; cursor: not-allowed; }

.start-btn {
  padding: 16px 46px;
  border: none;
  border-radius: 999px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(145deg, #4ade80, #22c55e);
  cursor: pointer;
  box-shadow: 0 5px 20px rgba(0, 0, 0, .3);
  transition: transform .2s ease, box-shadow .2s ease;
}

.start-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 9px 28px rgba(0, 0, 0, .4);
}

.start-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Messages & score ---------- */
.message {
  min-height: 44px;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, .3);
}

.message.win  { color: #bbf7d0; }
.message.loss { color: #fca5a5; }

.score-display {
  color: rgba(255, 255, 255, .95);
  font-size: 1.05rem;
}

/* ---------- Small screens ---------- */
@media (max-width: 520px) {
  h1 { font-size: 1.7rem; }
  .mode-btn { padding: 10px 18px; font-size: .88rem; }
  .start-btn { padding: 14px 32px; font-size: 1.05rem; }
  .message { font-size: 1.15rem; }
}

/* ============================================
   SHELL GAME SWAP ANIMATION
   ============================================ */

/* Base panel positioning for absolute movement */
.door-panel.swappable {
  position: relative;
  z-index: 1;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Active swap - panels lift up for visibility */
.door-panel.swap-active {
  z-index: 20;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
  transform: scale(1.08) !important;
}

/* Swap Direction A - Left/Up */
.door-panel.swap-a {
  animation: swapLeft 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Swap Direction B - Right/Down */
.door-panel.swap-b {
  animation: swapRight 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Keyframe animations for visual swap */
@keyframes swapLeft {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(-30%, -20%) scale(1.15);
    opacity: 0.7;
  }
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
}

@keyframes swapRight {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(30%, 20%) scale(1.15);
    opacity: 0.7;
  }
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
}

/* Glowing effect to highlight swapped panels */
@keyframes swapGlow {
  0%, 100% {
    box-shadow: 0 4px 15px rgba(186, 228, 0, 0.2);
  }
  50% {
    box-shadow: 0 8px 35px rgba(255, 215, 0, 0.6);
  }
}

.door-panel.swap-active .door-door {
  animation: swapGlow 0.35s ease;
}

/* Shine effect across the door surface */
@keyframes swapShine {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

.door-panel.swap-active .door-door::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.6) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: swapShine 0.35s ease;
  pointer-events: none;
  z-index: 11;
}

/* Disabled during swap to prevent clicks */
.panel-grid.shuffling-doors .door-panel {
  cursor: not-allowed;
  pointer-events: none;
}