/* Import friendly rounded font */
@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;700;900&display=swap");

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Nunito", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: white;
  cursor: pointer;
}

/* ========== DESKTOP PREVIEW STYLES ========== */
.preview-body {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.preview-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.mobile-frame {
  height: min(85vh, 700px);
  width: calc(min(85vh, 700px) / 2.17);
  border: 8px solid #1a1a1a;
  border-radius: 45px;
  background: linear-gradient(180deg, #003d6b 0%, #005696 40%, #0078c8 100%);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 0 2px #333, 0 20px 50px rgba(0,0,0,0.5);
}

.notch {
  width: 90px;
  height: 25px;
  background-color: #000;
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 20px;
  z-index: 1000;
}

.iframe-wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  border-radius: 37px;
}

.home-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 4px;
  background-color: rgba(255,255,255,0.3);
  border-radius: 2px;
  z-index: 1000;
}

/* Canvas inside frame */
.iframe-wrapper canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

/* All game UI elements use absolute positioning within frame */
#cloud-overlay,
#score-container,
#perfect-indicator,
#layer-name,
#tutorial-hand,
#instructions,
#results,
#victory {
  position: absolute;
}

/* Responsive for smaller laptops */
@media (max-height: 700px) {
  .mobile-frame {
    height: min(80vh, 550px);
    width: calc(min(80vh, 550px) / 2.17);
    border-width: 6px;
    border-radius: 38px;
  }
  .iframe-wrapper { border-radius: 32px; }
  .notch { width: 75px; height: 22px; top: 10px; }
}

/* Large desktop screens */
@media (min-height: 900px) {
  .mobile-frame {
    height: min(85vh, 800px);
    width: calc(min(85vh, 800px) / 2.17);
    border-width: 10px;
    border-radius: 50px;
  }
  .iframe-wrapper { border-radius: 40px; }
  .notch { width: 100px; height: 28px; top: 14px; }
}

/* ========== MOBILE: FULLSCREEN MODE ========== */
@media (max-width: 768px) {
  .preview-body {
    background: linear-gradient(180deg, #003d6b 0%, #005696 40%, #0078c8 100%);
  }

  .preview-container {
    padding: 0;
    width: 100%;
    height: 100%;
  }

  .mobile-frame {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .notch,
  .home-indicator {
    display: none;
  }

  .iframe-wrapper {
    border-radius: 0;
  }

  .iframe-wrapper canvas {
    position: fixed;
  }

  #cloud-overlay,
  #score-container,
  #perfect-indicator,
  #layer-name,
  #tutorial-hand,
  #instructions,
  #results,
  #victory {
    position: fixed;
  }
}

/* ========== GAME UI STYLES ========== */

/* Cloud overlay effect */
#cloud-overlay {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(ellipse 100px 60px at 10% 15%, rgba(255,255,255,0.15) 0%, transparent 70%),
    radial-gradient(ellipse 150px 80px at 85% 10%, rgba(255,255,255,0.12) 0%, transparent 70%),
    radial-gradient(ellipse 120px 70px at 25% 25%, rgba(255,255,255,0.1) 0%, transparent 70%),
    radial-gradient(ellipse 180px 90px at 70% 20%, rgba(255,255,255,0.08) 0%, transparent 70%),
    radial-gradient(ellipse 100px 50px at 50% 8%, rgba(255,255,255,0.1) 0%, transparent 70%);
}

/* Score container */
#score-container {
  top: 20px;
  right: 20px;
  z-index: 100;
  text-align: center;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 12px 24px;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

#score-label {
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 2px;
  opacity: 0.9;
  margin-bottom: 4px;
}

#score {
  font-size: 3em;
  font-weight: 900;
  line-height: 1;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Perfect stack indicator */
#perfect-indicator {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 150;
  font-size: 2.5em;
  font-weight: 900;
  color: #FFD700;
  text-shadow:
    0 0 10px rgba(255, 215, 0, 0.8),
    2px 2px 4px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}

#perfect-indicator.show {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

/* Layer name indicator */
#layer-name {
  top: 30%;
  left: 50%;
  transform: translateX(-50%) scale(0);
  z-index: 150;
  font-size: 1.4em;
  font-weight: 900;
  color: white;
  text-shadow:
    0 0 10px rgba(0, 0, 0, 0.5),
    2px 2px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s ease-out, opacity 0.3s ease-out;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 20px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

#layer-name.show {
  transform: translateX(-50%) scale(1);
  opacity: 1;
}

/* Modal screens shared styles */
#instructions,
#results,
#victory {
  display: none;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  z-index: 200;
  background: linear-gradient(180deg,
    rgba(0, 53, 96, 0.95) 0%,
    rgba(0, 86, 150, 0.9) 50%,
    rgba(0, 120, 200, 0.85) 100%);
  backdrop-filter: blur(5px);
}

.iframe-wrapper:hover #instructions,
body:hover #instructions {
  display: flex;
}

#results,
#victory {
  cursor: default;
}

.content {
  max-width: 280px;
  padding: 30px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  backdrop-filter: blur(10px);
}

/* Logo styles */
.logo {
  margin-bottom: 20px;
}

.logo-icon {
  font-size: 3em;
  display: block;
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

.logo h1 {
  font-size: 1.8em;
  font-weight: 900;
  letter-spacing: 3px;
  margin: 0;
  background: linear-gradient(180deg, #FFD700 0%, #FFA500 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo h2 {
  font-size: 1em;
  font-weight: 700;
  letter-spacing: 2px;
  margin: 6px 0 0;
  opacity: 0.9;
}

/* Text styles */
.tagline {
  font-size: 1.1em;
  font-weight: 700;
  margin-bottom: 12px;
  color: #FFD700;
}

.hint {
  font-size: 0.85em;
  opacity: 0.8;
  margin-bottom: 16px;
  line-height: 1.4;
}

.cta {
  font-size: 1em;
  font-weight: 700;
  margin-top: 20px;
}

.key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: 900;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Game over screen */
.game-over-icon,
.victory-icon {
  font-size: 3em;
  margin-bottom: 12px;
}

#results h2,
#victory h2 {
  font-size: 1.6em;
  font-weight: 900;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

.final-score-label {
  font-size: 0.9em;
  opacity: 0.8;
  margin-bottom: 6px;
}

.final-score {
  font-size: 2em;
  font-weight: 900;
  color: #FFD700;
  margin-bottom: 20px;
}

.victory-text {
  font-size: 1em;
  margin-bottom: 20px;
  line-height: 1.4;
}

/* Play again button */
#play-again-btn,
#play-again-victory-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(180deg, #D2B48C 0%, #C4A574 100%);
  color: #4A3728;
  border: none;
  border-radius: 50px;
  padding: 12px 24px;
  font-size: 1em;
  font-weight: 900;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  margin-bottom: 12px;
}

#play-again-btn:hover,
#play-again-victory-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#play-again-btn:active,
#play-again-victory-btn:active {
  transform: scale(0.98);
}

.btn-icon {
  font-size: 1.1em;
}

/* Victory screen specific */
#victory .content {
  background: linear-gradient(180deg,
    rgba(255, 215, 0, 0.2) 0%,
    rgba(255, 165, 0, 0.1) 100%);
  border-color: rgba(255, 215, 0, 0.4);
}

/* Tutorial hand animation */
#tutorial-hand {
  bottom: 35%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#tutorial-hand.show {
  opacity: 1;
}

.hand-icon {
  font-size: 3em;
  animation: tap-bounce 1s ease-in-out infinite;
}

.tap-text {
  font-size: 1em;
  font-weight: 900;
  color: #FFD700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  letter-spacing: 3px;
  animation: tap-fade 1s ease-in-out infinite;
}

/* Animations */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes tap-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

@keyframes tap-fade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Mobile responsive */
@media (max-width: 768px) {
  .content {
    max-width: 320px;
    padding: 35px;
  }

  .logo-icon {
    font-size: 3.5em;
  }

  .logo h1 {
    font-size: 2.2em;
  }

  #score-container {
    top: 15px;
    right: 15px;
    padding: 10px 20px;
  }

  #score {
    font-size: 2.5em;
  }

  #play-again-btn,
  #play-again-victory-btn {
    padding: 14px 28px;
    font-size: 1.1em;
  }
}

/* Prevent text selection */
body {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

canvas {
  touch-action: none;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}
