/**
 * Egg Game CSS
 * Two layouts: portrait (mobile) and landscape (desktop/widescreen).
 * Designed to pixel-match the reference designs.
 */

/* ==========================================
   RESET & BASE
   ========================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================
   BACKGROUND
   ========================================== */

#background-container {
  position: fixed;
  inset: 0;
  background-image: url('/assets/images/background/background-web.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
}

/* ==========================================
   APP — fills viewport, stacks vertically
   ========================================== */

#app {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ==========================================
   HEADER
   ========================================== */

#header {
  width: 100%;
  text-align: center;
  flex-shrink: 0;
}

#header-logo {
  max-height: 2.5vh;
  width: auto;
  display: inline-block;
  margin-top: 3vh;
}

/* ==========================================
   BANNER
   ========================================== */

#banner {
  width: 100%;
  text-align: center;
  flex-shrink: 0;
}

#banner-img {
  width: 100%;
  display: block;
}

/* ==========================================
   MAIN CONTENT — eggs, instruction, buttons
   Centred as a group
   ========================================== */

#main-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* ==========================================
   EGGS
   ========================================== */

#eggs-area {
  display: grid;
  justify-content: center;
  width: 100%;
}

/* Stack both grids in the same cell */
#eggs-grid,
#egg-hit-zones {
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto;
  justify-items: center;
  align-items: center;
}

.egg-slot {
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.egg-slot.cracked {
  /* no cursor change needed — hit zones handle clicks */
}

/* ==========================================
   EGG HIT ZONES — identical grid on top, clean click targets
   ========================================== */

#egg-hit-zones {
  z-index: 2;
}

.egg-hit-zone {
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.egg-hit-zone:active {
  /* visual feedback is applied to the egg-slot via JS */
}

.egg-img {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.35))
    drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25));
}

/* ==========================================
   INSTRUCTION BAR
   ========================================== */

#instruction-bar {
  display: flex;
  justify-content: center;
  width: 100%;
}

#instruction-content {
  background-image: url('/assets/images/background/backdrop-instruction-website.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  text-align: center;
}

#instruction-content p {
  color: white;
  line-height: 1.2;
  font-weight: 700;
  text-shadow:
    0 2px 6px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ==========================================
   BOTTOM BUTTONS
   ========================================== */

#bottom-buttons {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: 4vh;
}

.btn-option {
  background-image: url('/assets/images/buttons/button-option.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-color: transparent;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.btn-option:active {
  transform: scale(0.95);
}

.btn-option span {
  color: #7a3d00;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ==========================================
   MODAL
   ========================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

#modal-container {
  width: 90%;
  max-width: 520px;
  animation: scaleIn 0.3s ease;
}

#modal-content {
  position: relative;
  background-image: url('/assets/images/background/backdrop-popup.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding: 3rem 2.5rem;
  min-height: 350px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#modal-body {
  color: white;
  text-align: center;
  font-size: 1rem;
  line-height: 1.6;
}

#modal-body h2 {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 0.4rem;
}

#modal-body .reward-congrats {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

#modal-body .reward-ticket-img {
  display: block;
  margin: 0 auto 1rem;
  max-width: 60%;
  height: auto;
}

#modal-body .reward-won-title {
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 0.3rem;
}

#modal-body .reward-won-desc {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-bottom: 1.2rem;
}

#modal-body .reward-close-btn {
  display: block;
  margin: 0 auto;
  background-image: url('/assets/images/buttons/button-option.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-color: transparent;
  border: none;
  cursor: pointer;
  color: #7a3d00;
  font-weight: 700;
  font-size: 1rem;
  padding: 1.2vh 6vw;
  min-width: 50%;
  transition: transform 0.15s ease;
}

#modal-body .reward-close-btn:active {
  transform: scale(0.95);
}

#modal-body .reward-brand {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-bottom: 0.6rem;
}

#modal-body .reward-desc {
  font-size: 0.85rem;
  opacity: 0.9;
}

#modal-body .comeback-msg {
  color: white;
  line-height: 1.2;
  font-weight: 700;
  text-shadow:
    0 2px 6px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.25);
  font-size: 1rem;
}

/* ==========================================
   LOADING STATE
   ========================================== */

#app.loading .egg-slot {
  pointer-events: none;
  opacity: 0.7;
}

/* ==========================================
   LOADING OVERLAY
   ========================================== */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading-overlay.hidden {
  display: none;
}

#loading-spinner {
  width: 60px;
  height: 60px;
  border: 5px solid #e8c9a8;
  border-top: 5px solid #d4a87c;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================
   ANIMATIONS
   ========================================== */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ==========================================
   EGG SHAKE / WOBBLE
   ========================================== */

.egg-shake {
  animation: eggShake 0.12s ease-in-out 5;
}

@keyframes eggShake {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-6deg);
  }
  75% {
    transform: rotate(6deg);
  }
}

/* ==========================================
   EGG REVEAL PULSE
   ========================================== */

.egg-reveal-pulse {
  animation: eggPulse 0.5s ease-out;
}

@keyframes eggPulse {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

/* ==========================================
   SCREEN FLASH
   ========================================== */

.screen-flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    circle,
    rgba(255, 215, 0, 0.7),
    rgba(255, 255, 255, 0.9)
  );
  z-index: 300;
  pointer-events: none;
  animation: flashFade 0.4s ease-out forwards;
}

@keyframes flashFade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ==========================================
   CONFETTI
   ========================================== */

.confetti-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 150;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  opacity: 1;
  animation: confettiFall linear forwards;
}

.confetti-circle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.confetti-square {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.confetti-strip {
  width: 5px;
  height: 14px;
  border-radius: 1px;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg) scale(0.5);
    opacity: 0;
  }
}

/* ==========================================================
   PORTRAIT — mobile / tall viewports
   Reference: Mobile-01.png
   - Title at top ~7%
   - Eggs large, ~28% vw each, tightly grouped ~75% total
   - Instruction bar ~80% width
   - Buttons at bottom ~40% each
   ========================================================== */

@media (orientation: portrait), (max-aspect-ratio: 4/3) {
  #header {
    padding: 6vh 1rem 0;
  }

  #header-logo {
    max-height: 2.5vh;
  }

  #banner-img {
    width: 100%;
  }

  #main-content {
    margin-top: 0;
  }

  /* Eggs — 3-col grid, 2 rows, matching original egg size */
  #eggs-grid,
  #egg-hit-zones {
    width: 95vw;
  }

  .egg-slot {
    margin: -6vh -20vw;
    width: 200%;
  }

  .egg-hit-zone {
    margin: -6vh -20vw;
  }

  /* Instruction */
  #instruction-bar {
    margin-top: 8vh;
  }

  #instruction-content {
    width: 75vw;
    padding: 2vh 3vw;
  }

  #instruction-content p {
    font-size: 1rem;
  }

  /* Buttons */
  #bottom-buttons {
    margin-top: 0;
    gap: 3vw;
  }

  .btn-option {
    padding: 1.2vh 5vw;
    min-width: 38vw;
  }

  .btn-option span {
    font-size: 0.9rem;
  }
}

/* ==========================================================
   PORTRAIT TABLET — iPads in portrait (min-width 768px)
   Overrides portrait rules for larger screens
   ========================================================== */

@media (orientation: portrait) and (min-width: 700px) {
  #banner-img {
    width: 70vw;
    display: inline-block;
  }

  #eggs-grid,
  #egg-hit-zones {
    width: 80vw;
  }

  .egg-slot {
    margin: -4vh -12vw;
    width: 180%;
  }

  .egg-hit-zone {
    margin: -4vh -12vw;
  }

  #instruction-bar {
    margin-top: 10vh;
  }

  #instruction-content {
    width: 55vw;
  }

  #bottom-buttons {
    margin-top: 4vh;
    padding-bottom: 4vh;
  }

  .btn-option {
    min-width: 25vw;
  }
}

/* ==========================================================
   TABLET — landscape tablets & small laptops
   (landscape between 4/3 and 16/10)
   ========================================================== */

@media (orientation: landscape) and (min-aspect-ratio: 4/3) and (max-width: 1199px) {
  #header {
    padding: 4vh 1rem 0;
  }

  #banner-img {
    width: 50vw;
    display: inline-block;
  }

  #main-content {
    margin-top: 0;
  }

  /* Eggs */
  #eggs-area {
    margin-top: 8vh;
  }

  #eggs-grid,
  #egg-hit-zones {
    width: 65vw;
  }

  .egg-slot {
    margin: -8vh -5vw;
    width: 190%;
  }

  .egg-hit-zone {
    margin: -8vh -5vw;
  }

  /* Instruction */
  #instruction-bar {
    margin-top: 12vh;
  }

  #instruction-content {
    width: 45vw;
    padding: 3vh 3vw;
  }

  #instruction-content p {
    font-size: 1rem;
  }

  /* Buttons */
  #bottom-buttons {
    margin-top: 4vh;
    padding-bottom: 4vh;
    gap: 2vw;
  }

  .btn-option {
    padding: 1.5vh 4vw;
    min-width: 18vw;
  }

  .btn-option span {
    font-size: 0.9rem;
  }
}

/* ==========================================================
   DESKTOP — widescreen / large screens
   ========================================================== */

@media (orientation: landscape) and (min-aspect-ratio: 4/3) and (min-width: 1200px) {
  #header {
    padding: 4vh 1rem 0;
  }

  #banner-img {
    width: 30vw;
    display: inline-block;
  }

  #main-content {
    margin-top: 0;
  }

  /* Eggs */
  #eggs-area {
    margin-top: 14vh;
  }

  #eggs-grid,
  #egg-hit-zones {
    width: 50vw;
  }

  .egg-slot {
    margin: -16vh -3vh;
    width: 190%;
  }

  .egg-hit-zone {
    margin: -16vh -3vh;
  }

  /* Instruction */
  #instruction-bar {
    margin-top: 14vh;
  }

  #instruction-content {
    width: 30vw;
    padding: 3.5vh 2.5vw;
  }

  #instruction-content p {
    font-size: 1.05rem;
  }

  /* Buttons */
  #bottom-buttons {
    margin-top: 4vh;
    gap: 1.5vw;
  }

  .btn-option {
    padding: 2vh 3vw;
    min-width: 13vw;
  }

  .btn-option span {
    font-size: 0.95rem;
  }

  .egg-img {
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.3));
  }
}
