/* =========================
  BASE RESET
========================= */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: manipulation;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  -webkit-user-drag: none;
  user-select: none;
}

/* =========================
  APP WRAPPER
========================= */
.app {
  width: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* =========================
  STAGE
========================= */
.stage {
  position: relative;
  width: min(500px, 100vw);
  height: 100dvh;
  overflow: hidden;
}

/* Background */
.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* Header */
.header {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: 90%;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.header img {
  width: min(320px, 78%);
}

/* =========================
  GAME AREA
========================= */
.game {
  position: absolute;
  left: 50%;
  top: 66%;
  transform: translate(-50%, -50%);
  width: 84%;
  aspect-ratio: 1 / 1;
  z-index: 4;
}

/* optional layer */
.dragon-layer-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
}

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

/* =========================
  ✅ SCRATCH AREA (MAKE IT SMALLER HERE)
========================= */
.scratch-area {
  position: absolute;

  /* ✅ CONTROL SIZE + POSITION */
  width: 103%; /* smaller => lower */
  height: 68%; /* smaller => lower */
  left: 50%;
  top: 50%; /* move up/down */
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* grid fills scratch-area */
.grid-container {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 12px;
  bottom: 10px;
}

.grid-item {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
}

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

/* canvas fills scratch-area exactly */
.global-scratch-canvas {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
}

/* =========================
  POPUPS
========================= */
.pop-out-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  background: rgba(0, 0, 0, 0);
}

.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%);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.3s ease,
    visibility 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

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

.pop-out-win1 img,
.pop-out-win2 img {
  width: min(460px, 88vw);
  height: auto;
}

.btn-win {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-win img {
  width: min(210px, 78vw);
  cursor: pointer;
  transition: transform 0.2s ease;
}

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

/* =========================
  SMALL DEVICES
========================= */
@media (max-width: 440px) {
  /* ... your other rules ... */
  .scratch-area {
    width: 110%;
    height: 75%;
    top: 50%;
    left: 51%;
    transform: translate(-50%, -50%);
  }
  .pop-out-win1,
  .pop-out-win2 {
    position: fixed;
    top: 42%; /* ✅ a bit higher */
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      opacity 0.3s ease,
      visibility 0.3s ease;

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
  }

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

  /* ✅ MAKE POPUP IMAGE BIG */
  .pop-out-win1 img,
  .pop-out-win2 img {
    width: 92vw; /* ✅ bigger */
    max-width: 520px; /* ✅ limit on big phones */
    max-height: 60vh; /* ✅ prevent overflow */
    height: auto;
  }

  /* ✅ MAKE BUTTONS BIG TOO */
  .btn-win img {
    width: 78vw;
    max-width: 220px;
  }
}
