html,
body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000;
  overflow-x: hidden;
  overflow-y: auto;
}

img {
  max-width: 100%;
  height: auto;
  image-rendering: auto;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: block;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  will-change: auto;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

.container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  min-height: 100vh;
}

.bg-image {
  width: 40%;
  min-width: 40%;
  height: auto;
  max-height: 100vh;
  object-fit: contain;
  object-position: center;
  display: block;
  image-rendering: auto;
  backface-visibility: hidden;
}

.header-wrapper {
  position: absolute;
  top: 6%;
  left: 43%;
  transform: translate(0%, 0%);
  z-index: 10;
  pointer-events: none;
  width: 50%;
  max-width: 50%;
}

.header-wrapper img {
  width: 100%;
  height: auto;
  max-width: 30%;
  object-fit: contain;
  display: block;
  image-rendering: auto;
  backface-visibility: hidden;
}

.grid-wrapper {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 25%;
  height: 60%;
  max-width: calc(40% - 40px);
  pointer-events: none;
}

.grid-frame {
  position: absolute;
  top: 35%;
  left: 7%;
  width: 90%;
  height: 50%;
  object-fit: fill;
  z-index: 1;
  pointer-events: none;
}

/* ✅ Global scratch canvas overlay */
.global-scratch-canvas {
  position: absolute;
  top: 35%;
  left: 7%;
  width: 90%;
  height: 50%;
  z-index: 10;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}

.dragon-layer-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
}

.dragon-layer-bg.show {
  opacity: 1;
  visibility: visible;
}

.grid-container {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  top: 30%;
  left: 7%;
  width: 89%;
  height: 50%;
  padding: 10px;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 2;
  background: none;
}

.grid-item {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.grid-item img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  display: block;
}

/* Popup */
.pop-out-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  pointer-events: none;
}

.pop-out-backdrop.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.pop-out-win1,
.pop-out-win2 {
  position: fixed;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  pointer-events: none;
}

.pop-out-win1.show,
.pop-out-win2.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.pop-out-win1 img,
.pop-out-win2 img {
  max-width: 450px;
  min-width: 200px;
  width: auto;
  height: auto;
  display: block;
}

.btn-win {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  margin-top: 50px;
}

.btn-win img {
  max-width: 200px;
  min-width: 200px;
  width: auto;
  height: auto;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease;
}

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

/* MOBILE */
/* MOBILE */
@media (max-width: 768px) {

  html,
  body {
    overflow: hidden;
    /* Prevent scrollbars in inspect mode */
    height: 100%;
  }

  .container {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .bg-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .header-wrapper {
    top: 2%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    display: flex;
    justify-content: center;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    width: 100%;
    max-width: 100%;
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: unset;
    aspect-ratio: 3 / 4.2;
  }

  .grid-frame {
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
  }

  .grid-item {
    top: 0;
    /* Reset manual offset */
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .grid-item img {
    width: 75%;
    /* More reasonable size than 50% */
    height: 75%;
    object-fit: contain;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 45.5%;
    /* Unified baseline position */
    left: 50%;
    transform: translate(-50%, -50%);
    width: 88%;
    height: 43%;
    gap: 4px;
  }

  .pop-out-win1 img,
  .pop-out-win2 img {
    max-width: 85vw;
  }

  .btn-win img {
    max-width: 180px;
    min-width: 140px;
  }
}

@media (max-width: 440px) {
  .header-wrapper {
    top: 5%;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    top: 71.2%;
  }

  .grid-item img {
    width: 50%;
    height: 50%;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 42.5%;
    width: 86.5%;
    height: 42%;
  }
}

@media (max-width: 428px) {
  .bg-image {
    width: 100%;
    min-width: 100%;
    /* height: auto; */
    max-height: 100vh;
    object-fit: fill;
  }

  .header-wrapper {
    top: 5%;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    top: 69%;
  }

  .grid-item {
    top: -15px;
  }

  .grid-item img {
    width: 50%;
    height: 50%;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 45%;
    width: 81%;
    height: 45%;
  }
}

@media (max-width: 430px) {
  .bg-image {
    width: 100%;
    min-width: 100%;
    /* height: auto; */
    max-height: 100vh;
    object-fit: fill;
  }

  .header-wrapper {
    top: 5%;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    top: 69%;
  }

  .grid-item {
    top: -15px;
  }

  .grid-item img {
    width: 50%;
    height: 50%;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 45%;
    width: 81%;
    height: 45%;
  }
}


@media (max-width: 390px) {
  .header-wrapper {
    top: 5%;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    top: 69%;
  }

  .grid-item {
    top: -15px;
  }

  .grid-item img {
    width: 50%;
    height: 40%;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 45%;
    width: 81%;
    height: 47%;
  }

  .btn-win {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
}

@media (max-width: 360px) {
  .bg-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .header-wrapper {
    top: 13%;
  }

  .header-wrapper img {
    max-width: 55%;
  }

  .grid-wrapper {
    top: 66%;
  }

  .grid-container,
  .global-scratch-canvas {
    top: 46%;
    width: 80%;
    height: 40%;
  }
}