/* === RESET & BASE === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

/* === GAME CONTAINER === */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

/* === SCREEN SYSTEM === */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 1.2s ease-in-out;
  pointer-events: none;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* Inner wrapper maintains 3:2 aspect ratio and centers content */
.screen-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  max-width: calc(100vh * 1536 / 1024);
  max-height: calc(100vw * 1024 / 1536);
  overflow: hidden;
}

.screen-bg-picture {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.screen-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 0;
}

/* === LOADER SCREEN === */
.loader-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: 80%;
  max-width: 420px;
}

#loader-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.4rem;
  color: #ffd700;
  text-shadow:
    0 0 10px rgba(255, 215, 0, 0.6),
    0 0 30px rgba(255, 180, 50, 0.3);
  margin-bottom: 40px;
  line-height: 1.6;
  animation: loader-title-pulse 2s ease-in-out infinite;
}

@keyframes loader-title-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#loader-bar-track {
  width: 100%;
  height: 20px;
  border: 2px solid #c9a84c;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.6);
  padding: 3px;
  box-shadow:
    0 0 10px rgba(201, 168, 76, 0.2),
    inset 0 0 8px rgba(0, 0, 0, 0.5);
}

#loader-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8b6914, #c9a84c, #ffd700);
  border-radius: 1px;
  transition: width 0.3s ease-out;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
  position: relative;
}

#loader-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
  border-radius: 1px 1px 0 0;
}

#loader-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  color: #c9a84c;
  margin-top: 18px;
  letter-spacing: 2px;
}

#loader-text::after {
  content: '...';
  animation: loader-dots 1.5s step-end infinite;
}

@keyframes loader-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* === WELCOME SCREEN OVERLAYS === */
.overlay {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
  user-select: none;
}

.overlay img {
  width: 100%;
  height: auto;
  display: block;
}

/* Title: upper portion of the arch */
.overlay-title {
  top: 5%;
  width: 58%;
}

/* Start button: center-lower area of the arch */
.overlay-start {
  top: 50%;
  width: 32%;
  pointer-events: auto;
  cursor: pointer;
  animation: pulse 2.5s ease-in-out infinite;
}

.overlay-start:hover {
  animation: none;
  filter: brightness(1.3) drop-shadow(0 0 20px rgba(255, 215, 0, 0.8));
}

.overlay-start:active {
  filter: brightness(1.5) drop-shadow(0 0 30px rgba(255, 215, 0, 1));
}

/* Copyright: flush at the very bottom */
.overlay-copyright {
  bottom: 0;
  top: auto;
  width: 42%;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: translateX(-50%) scale(1); }
  50% { opacity: 0.6; transform: translateX(-50%) scale(1.03); }
}

/* === GAME SCREEN: LOCK === */
#lock-area {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: 22%;
  z-index: 2;
}

#lock-image {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 15px rgba(180, 160, 255, 0.5));
  animation: lock-float 3s ease-in-out infinite;
}

@keyframes lock-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

/* === GAME SCREEN: KEYS AREA === */
#keys-area {
  position: absolute;
  bottom: 4%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 4%;
  width: 85%;
  z-index: 2;
}

/* Each key-arch unit */
.key-arch-unit {
  flex: 0 0 28%;
  cursor: pointer;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.arch-container {
  position: relative;
  width: 100%;
  aspect-ratio: 470 / 543;
}

/* Arch backgrounds (passive and active stacked) */
.arch-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.3s ease;
}

.arch-bg-active {
  opacity: 0;
}

.arch-bg-passive {
  opacity: 1;
}

/* Hover: layer active on top of passive (passive stays visible = no flicker) */
.key-arch-unit:hover .arch-bg-active {
  opacity: 1;
}

/* Key image centered inside the arch */
.key-image {
  position: absolute;
  top: 54%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: auto;
  z-index: 1;
  transition: transform 0.3s ease;
}

.key-arch-unit:hover .key-image {
  transform: translate(-50%, -50%) scale(1.08);
}

/* === KEY SELECTION ANIMATIONS === */

/* Other keys fade out */
.key-arch-unit.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* Lock active arch bg on after click */
.arch-container.arch-locked-active .arch-bg-active {
  opacity: 1;
}

/* Elevate selected unit above siblings during animation */
.key-arch-unit.centering {
  z-index: 10;
  position: relative;
}

/* Key rises out of the arch and hovers above it */
.key-image.key-rise {
  transition: transform 0.8s ease-out, filter 0.8s ease-out;
  transform: translate(-50%, -180%) scale(1.1);
  filter: drop-shadow(0 0 25px rgba(255, 215, 0, 0.7));
}

/* Key floats in the air: slow wiggle + breathing scale + retro glow */
.key-image.key-hover-glow {
  animation: hover-wiggle-breathe 3s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(255, 255, 240, 0.9))
          drop-shadow(0 0 30px rgba(255, 215, 0, 0.8))
          drop-shadow(0 0 60px rgba(255, 180, 50, 0.4))
          drop-shadow(0 0 90px rgba(200, 150, 255, 0.3));
}

@keyframes hover-wiggle-breathe {
  0% {
    transform: translate(-50%, -180%) scale(1.1) rotate(0deg);
  }
  15% {
    transform: translate(-50%, -185%) scale(1.14) rotate(-4deg);
  }
  30% {
    transform: translate(-50%, -178%) scale(1.08) rotate(3deg);
  }
  50% {
    transform: translate(-50%, -188%) scale(1.16) rotate(-2deg);
  }
  70% {
    transform: translate(-50%, -176%) scale(1.09) rotate(4deg);
  }
  85% {
    transform: translate(-50%, -183%) scale(1.13) rotate(-3deg);
  }
  100% {
    transform: translate(-50%, -180%) scale(1.1) rotate(0deg);
  }
}

/* Vertical light beam from above — holds the key in suspension */
.arch-container.show-key-glow::before {
  content: '';
  position: absolute;
  top: -150%;
  left: 50%;
  transform: translateX(-50%);
  width: 40%;
  height: 250%;
  background:
    linear-gradient(180deg,
      transparent 0%,
      rgba(255, 255, 220, 0.08) 20%,
      rgba(255, 255, 220, 0.22) 40%,
      rgba(255, 235, 150, 0.35) 50%,
      rgba(255, 255, 220, 0.22) 60%,
      rgba(255, 255, 220, 0.08) 80%,
      transparent 100%
    ),
    linear-gradient(180deg,
      transparent 0%,
      transparent 35%,
      rgba(255, 255, 255, 0.12) 48%,
      rgba(255, 255, 255, 0.15) 50%,
      rgba(255, 255, 255, 0.12) 52%,
      transparent 65%,
      transparent 100%
    );
  z-index: 0;
  animation: beam-flicker 4s ease-in-out infinite;
  pointer-events: none;
  mask-image: linear-gradient(180deg, transparent 0%, white 8%, white 92%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, white 8%, white 92%, transparent 100%);
}

/* Glow pool where the beam hits the arch floor */
.arch-container.show-key-glow::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 20%;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(255, 235, 150, 0.4) 0%,
    rgba(255, 215, 0, 0.2) 35%,
    rgba(255, 200, 80, 0.08) 65%,
    transparent 100%
  );
  z-index: 0;
  animation: pool-pulse 2.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes beam-flicker {
  0% {
    opacity: 0.6;
    width: 40%;
  }
  12% {
    opacity: 0.85;
    width: 43%;
  }
  25% {
    opacity: 0.55;
    width: 38%;
  }
  40% {
    opacity: 0.95;
    width: 48%;
  }
  55% {
    opacity: 0.7;
    width: 42%;
  }
  70% {
    opacity: 1;
    width: 50%;
  }
  85% {
    opacity: 0.65;
    width: 40%;
  }
  100% {
    opacity: 0.6;
    width: 40%;
  }
}

@keyframes pool-pulse {
  0%, 100% {
    opacity: 0.4;
    transform: translateX(-50%) scaleX(1);
  }
  50% {
    opacity: 1;
    transform: translateX(-50%) scaleX(1.25);
  }
}

/* Upward-drifting particles inside the beam */
.beam-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
  opacity: 0;
}

.arch-container.show-key-glow .beam-particles {
  opacity: 1;
}

.beam-particles span {
  position: absolute;
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 240, 160, 0.95);
  box-shadow: 0 0 10px 4px rgba(255, 215, 0, 0.7);
  opacity: 0;
}

/* Stagger each particle: position, delay, size, speed */
.beam-particles span:nth-child(1) { left: 44%; animation: particle-rise-a 2.8s ease-out 0s infinite; }
.beam-particles span:nth-child(2) { left: 54%; animation: particle-rise-b 3.4s ease-out 0.3s infinite; width: 3px; height: 3px; }
.beam-particles span:nth-child(3) { left: 48%; animation: particle-rise-a 3.0s ease-out 0.7s infinite; width: 6px; height: 6px; }
.beam-particles span:nth-child(4) { left: 40%; animation: particle-rise-b 2.6s ease-out 1.1s infinite; width: 4px; height: 4px; }
.beam-particles span:nth-child(5) { left: 56%; animation: particle-rise-a 3.6s ease-out 1.5s infinite; }
.beam-particles span:nth-child(6) { left: 46%; animation: particle-rise-b 2.4s ease-out 1.9s infinite; width: 6px; height: 6px; box-shadow: 0 0 12px 5px rgba(255, 215, 0, 0.8); }
.beam-particles span:nth-child(7) { left: 52%; animation: particle-rise-a 3.2s ease-out 2.3s infinite; width: 3px; height: 3px; }
.beam-particles span:nth-child(8) { left: 42%; animation: particle-rise-b 2.9s ease-out 2.7s infinite; width: 4px; height: 4px; }

@keyframes particle-rise-a {
  0% {
    bottom: 35%;
    opacity: 0;
    transform: translateX(0) scale(0.4);
  }
  8% {
    opacity: 1;
    transform: translateX(2px) scale(1);
  }
  50% {
    opacity: 0.8;
    transform: translateX(-3px) scale(0.9);
  }
  85% {
    opacity: 0.4;
    transform: translateX(1px) scale(0.6);
  }
  100% {
    bottom: 130%;
    opacity: 0;
    transform: translateX(-1px) scale(0.2);
  }
}

@keyframes particle-rise-b {
  0% {
    bottom: 30%;
    opacity: 0;
    transform: translateX(0) scale(0.4);
  }
  8% {
    opacity: 1;
    transform: translateX(-2px) scale(1);
  }
  50% {
    opacity: 0.85;
    transform: translateX(4px) scale(0.85);
  }
  85% {
    opacity: 0.35;
    transform: translateX(-2px) scale(0.5);
  }
  100% {
    bottom: 125%;
    opacity: 0;
    transform: translateX(1px) scale(0.2);
  }
}

/* === POPUP (shared) === */
.game-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.game-popup-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.game-popup-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.game-popup-box {
  background: linear-gradient(135deg, #1a0a2e 0%, #2d1b4e 50%, #1a0a2e 100%);
  border: 3px solid #c9a84c;
  border-radius: 8px;
  padding: 36px 44px;
  text-align: center;
  max-width: 480px;
  width: 85%;
  box-shadow:
    0 0 30px rgba(201, 168, 76, 0.3),
    inset 0 0 30px rgba(0, 0, 0, 0.5);
  transform: scale(0.8);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-popup-overlay.visible .game-popup-box {
  transform: scale(1);
}

.game-popup-box h2 {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.4rem;
  margin-bottom: 18px;
  line-height: 1.4;
}

.game-popup-box p {
  color: #e0d5c1;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  line-height: 2;
  margin-bottom: 22px;
}

.game-popup-button {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  padding: 12px 24px;
  background: linear-gradient(180deg, #c9a84c, #8b6914);
  color: #1a0a2e;
  border: 2px solid #ffd700;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
}

.game-popup-button:hover {
  background: linear-gradient(180deg, #ffd700, #c9a84c);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.game-popup-button:active {
  transform: scale(0.95);
}

/* === RESULT POPUP (specifics) === */
#popup-box.win h2 {
  color: #ffd700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.7);
}

#popup-box.lose h2 {
  color: #ff4444;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

#promo-code-area {
  background: rgba(0, 0, 0, 0.4);
  border: 2px dashed #c9a84c;
  padding: 14px 18px;
  margin-bottom: 22px;
  border-radius: 4px;
}

#promo-code-area.hidden {
  display: none;
}

#promo-code {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.1rem;
  color: #ffd700;
  letter-spacing: 3px;
}

#popup-hint {
  color: #c9a84c;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  line-height: 2;
  margin-bottom: 18px;
}

#popup-hint.hidden {
  display: none;
}

.game-popup-button.copied {
  background: linear-gradient(180deg, #4caf50, #2e7d32);
  border-color: #66bb6a;
}

/* === START POPUP (specifics) === */
#start-popup-box.welcome h2 {
  color: #ffd700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.7);
}

#start-popup-box.error h2 {
  color: #ff4444;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

/* === MUSIC TOGGLE === */
#music-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(201, 168, 76, 0.5);
  border-radius: 6px;
  width: 48px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
  padding: 4px;
}

#music-toggle:hover {
  background: rgba(0, 0, 0, 0.65);
  border-color: #ffd700;
}

.sound-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sound-icon-playing {
  display: none;
}

#music-toggle.playing .sound-icon-playing {
  display: block;
}

#music-toggle.playing .sound-icon-muted {
  display: none;
}

/* === PORTRAIT / MOBILE === */
@media (orientation: portrait) {
  .screen-inner {
    max-width: calc(100vh * 1024 / 1536);
    max-height: calc(100vw * 1536 / 1024);
  }

  /* Welcome overlays repositioned for tall arch */
  .overlay-title {
    top: 8%;
    width: 75%;
  }

  .overlay-start {
    top: 42%;
    width: 45%;
  }

  .overlay-copyright {
    width: 60%;
  }

  /* Game screen: lock + keys layout for portrait */
  #lock-area {
    top: 8%;
    width: 22%;
  }

  #keys-area {
    bottom: 8%;
    width: 90%;
    gap: 3%;
  }

  .key-arch-unit {
    flex: 0 0 28%;
  }

  /* Key rise goes higher in portrait (more vertical room) */
  .key-image.key-rise {
    transform: translate(-50%, -200%) scale(1.15);
  }

  .key-image.key-hover-glow {
    animation-name: hover-wiggle-breathe-portrait;
  }

  /* Popup */
  .game-popup-box {
    width: 85%;
    padding: 28px 24px;
  }
}

@keyframes hover-wiggle-breathe-portrait {
  0% {
    transform: translate(-50%, -200%) scale(1.15) rotate(0deg);
  }
  15% {
    transform: translate(-50%, -206%) scale(1.19) rotate(-4deg);
  }
  30% {
    transform: translate(-50%, -197%) scale(1.12) rotate(3deg);
  }
  50% {
    transform: translate(-50%, -210%) scale(1.21) rotate(-2deg);
  }
  70% {
    transform: translate(-50%, -195%) scale(1.13) rotate(4deg);
  }
  85% {
    transform: translate(-50%, -204%) scale(1.18) rotate(-3deg);
  }
  100% {
    transform: translate(-50%, -200%) scale(1.15) rotate(0deg);
  }
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
  #lock-area {
    width: 22%;
    top: 4%;
  }

  #keys-area {
    gap: 2%;
    width: 95%;
    bottom: 2%;
  }

  .key-arch-unit {
    flex: 0 0 30%;
  }

  .overlay-title {
    top: 6%;
    width: 65%;
  }

  .overlay-start {
    top: 48%;
    width: 38%;
  }

  .overlay-copyright {
    width: 55%;
  }

  .game-popup-box {
    padding: 24px 20px;
    width: 90%;
  }

  .game-popup-box h2 {
    font-size: 1.1rem;
  }

  .game-popup-box p {
    font-size: 0.55rem;
  }

  #promo-code {
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  .key-image {
    width: 45%;
  }

  .overlay-title {
    width: 75%;
  }

  .overlay-start {
    width: 45%;
  }
}

