/* Foreground container art for Bandicoot Bags */
.bags-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  object-fit: contain;
}

/* Renderer layering: Bags uses the container as a background plate.
   Keep tiles/grid above it for interaction + visibility. */
body.bags.aps-use-renderer .aps-gr-root .scratch-container__art.bags-frame{
  z-index: 1 !important;
}

#grid.grid--3x3 {
    background: transparent; /* No grid background panel */
    border-radius: 2px;
	padding: 1.5%; /* Increase this value for a larger background area */
  box-sizing: border-box;
  z-index: 2;
}
/* =========================================================
   Bandicoot Bags – Shared MainUI Mount Layout (3x3)
   Clean, Responsive, Production Safe
========================================================= */

/* Keep the shared stage centering behavior.
   IMPORTANT: Bags adds extra elements inside .ui-stage (status, overlays).
   Those must NOT affect board centering (editor parity + exported config fidelity).
*/
body.bags .ui-stage{
  flex-direction: row;
}

/* Fullscreen background (driven by config assets.background/backgroundMobile). */
body.bags .bags-bg{
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--bags-bg-url, url("../../assets/background/desktop/alphas-jackpot-bags-desktop-BG.svg")) center / var(--bags-bg-fit, cover) no-repeat;
}

/* Keep the stage above the fullscreen background. */
body.bags #uiStage,
body.bags .ui-stage{
  z-index: 1;
}

/* Renderer mount sizing (16:9 reference space). The shared UI sets #uiGameMount
   height:100%, but .ui-stage does not have an explicit height. Give the mount a
   stable box so the renderer doesn't compute a near-zero scale. */
body.bags #uiGameMount{
  position: relative;
  width: 100%;
  max-width: 900px;
  height: auto;
  aspect-ratio: 16 / 9;
}

/* When using the shared renderer, we mount into #uiGameMount (keep it visible). */
body.bags.aps-use-renderer #uiGameMount{
  display: block;
}

/* Status text: make it an overlay so it doesn't shift the board. */
body.bags .bags-status{
  position: absolute;
  left: 50%;
  top: var(--bags-stage-top, 16px);
  transform: translateX(-50%);
  margin: 0;
  z-index: 60;
  pointer-events: none;
}

/* Single sizing knob for the whole board (container + grid + status width).
   Reduce this to shrink the game uniformly without changing ratios. */
body.bags{
  /* Keep this aligned with shared scratch-board wrapper max (720px).
     If this exceeds the wrapper, the scratch-container can overflow and lose
     centering, which breaks Studio Editor parity.
  */
  --bags-board-max: 720px;
}



/* ===== Board wrapper injected by mountBoard ===== */
.bags-board.boardWrap {
  width: 100%;
  max-width: min(92vw, 720px);
  margin: 0 auto;
  display: grid;
  place-items: center;
  pointer-events: none; /* grid re-enables */
}

.bags-board .boardContainer {
  position: relative;
  width: min(var(--bags-board-max, 560px), 92vw);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

/* ===== Game Card Background ===== */
.bags-card {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bags-card__art {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  border-radius: 0;
  background: var(--bags-bg-desktop, url("../../assets/background/desktop/alphas-jackpot-bags-desktop-BG.svg")) center / cover no-repeat;
  pointer-events: none;
}

@media (max-width: 820px){
  .bags-card__art{
    background-image: var(--bags-bg-mobile, url("../../assets/background/mobile-portrait/alphas-jackpot-bags-mobile-portrait-BG.svg"));
  }
}

/* =========================================================
   GRID OVERLAY (Perfect 3x3 Fit)
========================================================= */

/* Grid positioning is now handled by shared .scratch-grid vars from mountBoard(). */

/* =========================================================
   TILE STYLING
========================================================= */

#grid.grid--3x3 .tile {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.15);
  box-sizing: border-box;
  padding: var(--tile-pad, 0px);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.889), 0 1.5px 4px rgba(0,0,0,0.10);
  will-change: transform;
}

#grid.grid--3x3 .tile:hover {
  transform: scale(1.03);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

#grid.grid--3x3 .tile.is-pressing,
#grid.grid--3x3 .tile.is-pressing:hover {
  transform: scale(0.99);
}

#grid.grid--3x3 .tile.is-locked {
  cursor: default;
  transform: none;
}

#grid.grid--3x3 .tile.is-revealed {
  animation: bags-tile-pop 380ms cubic-bezier(.2,.9,.2,1) both;
}

/* Content wrapper */
#grid.grid--3x3 .tile__content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: perspective(700px) rotateX(var(--bags-tilt-y, 0deg)) rotateY(var(--bags-tilt-x, 0deg));
  transform-style: preserve-3d;
  transition: transform 140ms ease;
  will-change: transform;
}

/* Symbol icon */
#grid.grid--3x3 .tile__icon {
  width: 65%;
  height: 65%;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.4));
  pointer-events: none;
  will-change: transform;
}

#grid.grid--3x3 .tile.is-revealed .tile__icon {
  animation: bags-icon-pop 420ms cubic-bezier(.15,.9,.2,1) both;
}

/* Scratch layer */
#grid.grid--3x3 .tile__scratch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  pointer-events: auto;
  will-change: opacity;
}

/* Particle overlay (spawned by JS) */
.bags-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 6;
}

.bags-particle {
  position: absolute;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.45));
}

/* Parallax target (move art + grid together) */
body.bags .scratch-container {
  /* IMPORTANT: Compose with Studio Editor / config.json layout transforms.
     Shared MainUI sets --aps-board-x/y/scale from config.layout.*
     so we must NOT overwrite transform here. */
  transform:
    translate(var(--aps-board-x, 0px), var(--aps-board-y, 0px))
    scale(var(--aps-board-scale, 1))
    rotate(var(--aps-board-rot, 0deg))
    translate3d(calc(var(--bags-parallax-x, 0) * 1px), calc(var(--bags-parallax-y, 0) * 1px), 0);
  transform-origin: top left;
  will-change: transform;
}

/* Disable parallax (also avoids 3D transform subpixel/GPU rounding drift). */
body.bags.bags-no-parallax .scratch-container{
  transform: translate(var(--aps-board-x, 0px), var(--aps-board-y, 0px)) scale(var(--aps-board-scale, 1)) rotate(var(--aps-board-rot, 0deg));
}

/* =========================================================
   STATUS TEXT
========================================================= */

.bags-status {
  margin: 16px auto 0;
  width: min(var(--bags-board-max, 560px), 92vw);
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
}

/* =========================================================
   SPEECH BUBBLE
========================================================= */

.speech-bubble {
  position: absolute;
  top: 24px;
  right: 500px;
  left: auto;
  transform: none;
  display: none;
  z-index: 50;
  width: 180px;
  max-width: 60vw;
}

.speech-bubble.is-show {
  display: block;
  animation: bags-speech-pop 420ms cubic-bezier(.2,.9,.2,1) both;
}

.speech-bubble img {
  display: block;
  width: 100%;
  height: auto;
}

.speech-bubble .speech-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  /* Give the bubble tail / edges breathing room while keeping text centered */
  padding: 18% 12% 26%;
  transform: none;
  color: #fff;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 13px;
  text-align: center;
  width: 100%;
  height: 100%;
  margin: 0;
  line-height: 1.1;
}
@media (max-width: 600px) {
  .speech-bubble {
    top: 10px;
    right: 8px;
    width: 120px;
    max-width: 80vw;
  }
  .speech-bubble .speech-text {
    font-size: 11px;
    padding: 18% 12% 28%;
  }
}

/* =========================================================
   MOBILE ADJUSTMENTS
========================================================= */

@media (max-width: 768px) {

  .bags-board.boardWrap {
    margin-top: 30px;
  }

  .bags-board .boardContainer { --bags-grid-gap: 8px; }

  #grid.grid--3x3 .tile {
    border-radius: 14px;
  }

  .speech-bubble {
    top: 12%;
  }
}

@media (max-width: 600px) {
  .bags-board.boardWrap {
    max-width: 98vw;
    width: 100%;
    margin: 0 auto;
    display: grid;
    place-items: center;
    box-sizing: border-box;
  }

  .bags-board .boardContainer { --bags-grid-gap: 8px; }
}

/* =========================================================
   MOBILE UI FIT (Bags-specific)
   Reserve space for fixed header + bottom wallet/actions.
========================================================= */

@media (max-width: 560px) {
  body.bags{
    --bags-stage-top: calc(84px + env(safe-area-inset-top));
    --bags-stage-bottom: calc(220px + env(safe-area-inset-bottom));

    /* Slightly smaller on phones so controls fit. */
    --ui-scale: 0.84;
  }

  body.bags .ui-stage{
    min-height: 100vh;
    padding-top: var(--bags-stage-top);
    padding-bottom: var(--bags-stage-bottom);
    padding-left: 10px;
    padding-right: 10px;
    box-sizing: border-box;
  }

  /* Match the shared mobile header treatment, but start a bit earlier for this game. */
  body.bags .ui-header{
    top: 10px;
    left: 10px;
    right: 10px;
    padding: 10px 10px;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
  }
  body.bags .ui-game-logo{ height: 36px; }
  body.bags .ui-header-actions{ gap: 8px; }
  body.bags .ui-back,
  body.bags .ui-help,
  body.bags .ui-sound{
    padding: 9px 10px;
    font-size: 12px;
  }

  /* Keep the bottom bar closer to the screen edge on phones. */
  body.bags .ui-bottombar{
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100vw - 18px);
  }

  /* Footer is usually hidden behind the bottom bar anyway; remove it on small screens. */
  body.bags .ui-footer{
    display: none;
  }

  /* Prevent the board from being taller than the usable viewport between header and bottom bar. */
  body.bags .bags-board .boardContainer{
    width: min(
      var(--bags-board-max, 560px),
      96vw,
      calc(100vh - var(--bags-stage-top) - var(--bags-stage-bottom))
    );
  }

  /* Status text is more useful above the board on phones. */
  body.bags #uiGameMount{ order: 1; }
  body.bags .bags-status{
    order: 0;
    margin: 0 auto 10px;
    width: min(96vw, 520px);
    font-size: 12.5px;
  }

  /* Keep the speech bubble away from the fixed header. */
  body.bags .speech-bubble{
    top: calc(env(safe-area-inset-top) + 72px);
  }

  /* Remove the extra push-down on small screens (stage padding handles it). */
  body.bags .bags-board.boardWrap{
    margin-top: 0;
  }
}

/* =========================================================
   GAME OVERLAYS (Modal + Bonus)
   Ensure overlays never affect board layout
========================================================= */

/* Always respect hidden attribute even if other CSS exists */
body.bags .modal[hidden],
body.bags .bonus-overlay[hidden],
body.bags .bags-orientation[hidden],
body.bags #bonusLoading[style*="display:none"] {
  display: none !important;
}

/* =========================================================
   PORTRAIT-ONLY (Mobile)
   Block gameplay in landscape on touch devices.
========================================================= */

body.bags.bags-landscape-block #uiStage,
body.bags.bags-landscape-block .ui-bottombar,
body.bags.bags-landscape-block .ui-header{
  pointer-events: none;
}

body.bags .bags-orientation{
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 16px;
}

body.bags .bags-orientation__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
}

body.bags .bags-orientation__panel{
  position: relative;
  width: min(520px, 92vw);
  border-radius: 18px;
  background: rgba(10, 14, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  padding: 16px 16px 14px;
  text-align: center;
}

body.bags .bags-orientation__title{
  margin: 0 0 6px;
  font-weight: 950;
  letter-spacing: .2px;
  color: rgba(255,255,255,0.92);
}

body.bags .bags-orientation__text{
  margin: 0;
  font-weight: 800;
  color: rgba(255,255,255,0.86);
}

body.bags .modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
}

body.bags .modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(6px);
}

body.bags .modal__dialog {
  position: relative;
  width: min(560px, 92vw);
  max-height: min(80dvh, 760px);
  overflow: auto;
  border-radius: 18px;
  background: rgba(10, 14, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

body.bags .modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

body.bags .modal__title {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .2px;
}

body.bags .modal__content {
  padding: 12px 14px;
}

body.bags .modal__footer {
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* Bonus overlay basic layout (keeps your existing markup/assets) */
body.bags .bonus-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 16px;
}

/* When the bonus is open, softly blur the underlying game elements. */
body.bags.bags-bonus-open #uiGameMount,
body.bags.bags-bonus-open #apsGameView,
body.bags.bags-bonus-open .bags-status,
body.bags.bags-bonus-open .speech-bubble,
body.bags.bags-bonus-open .bags-bg {
  filter: blur(5px);
}

body.bags .bonus-overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
}

/* Content wrapper: keep it lightweight (no big modal UI panel). */
body.bags .bonus-overlay__content{
  position: relative;
  width: min(760px, 92vw);
  display: grid;
  justify-items: center;
  gap: 10px;
}

body.bags .bonus-overlay.is-enter .bonus-overlay__content{
  animation: bags-bonus-enter 520ms cubic-bezier(.2,.9,.2,1) both;
}

body.bags .bonus-overlay__prompt{
  margin: 10px auto 12px;
  text-align: center;
  font-weight: 900;
  letter-spacing: .2px;
  color: rgba(255,255,255,0.92);
}

body.bags .bonus-bags{
  width: min(640px, 92vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2vw, 18px);
  align-items: stretch;
}

body.bags .bonus-bag{
  position: relative;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 18px;
  padding: 0;
  cursor: pointer;
  transition: filter 160ms ease;
  opacity: 0;
  transform: translate3d(0, -40vh, 0) scale(0.92);
  will-change: transform, filter, opacity;
}

body.bags .bonus-bag:focus-visible{
  outline: 2px solid rgba(255, 239, 176, 0.55);
  outline-offset: 6px;
}

/* Entrance: drop in from the top */
body.bags .bonus-bag.is-drop{
  opacity: 1;
  animation: bags-bag-drop 560ms cubic-bezier(.18,.95,.15,1) both;
}

/* Landed: stable resting state (no animation by itself) */
body.bags .bonus-bag.is-landed{
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

/* After landing: quick glow pulse */
body.bags .bonus-bag.is-glow{
  opacity: 1;
  filter: drop-shadow(0 0 22px rgba(255, 239, 176, 0.40)) drop-shadow(0 22px 28px rgba(0,0,0,0.40));
  animation: bags-bag-glow 520ms cubic-bezier(.2,.9,.2,1) both;
}

/* After landing: glow + idle bounce/shake */
body.bags .bonus-bag.is-idle{
  opacity: 1;
  filter: drop-shadow(0 0 16px rgba(255, 239, 176, 0.28)) drop-shadow(0 22px 28px rgba(0,0,0,0.40));
  animation: bags-bag-idle 1400ms ease-in-out infinite;
}

body.bags .bonus-bag.is-picked{
  filter: drop-shadow(0 0 20px rgba(255, 239, 176, 0.36)) drop-shadow(0 26px 34px rgba(0,0,0,0.45));
}

body.bags .bonus-bag.is-revealed img{
  animation: bags-bag-reveal 520ms cubic-bezier(.2,.9,.2,1) both;
}
body.bags .bonus-bag:hover{
  filter: drop-shadow(0 0 18px rgba(255, 239, 176, 0.34)) drop-shadow(0 24px 30px rgba(0,0,0,0.42));
}

/* Hover: make the bag feel interactive (zoom + faster wiggle) */
body.bags .bonus-bag:hover img{
  transform: scale(1.1);
}

body.bags .bonus-bag.is-idle:hover{
  animation-duration: 720ms;
}
body.bags .bonus-bag:disabled{
  opacity: 0.70;
  cursor: not-allowed;
  transform: translate3d(0, 0, 0) scale(1);
  animation: none;
}
body.bags .bonus-bag img{
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 16px 26px rgba(0,0,0,0.45));
  transform: scale(1);
  transition: transform 160ms ease;
}

body.bags .bonus-bag__amount{
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%);
  min-width: 74px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,236,190,0.26);
  background: rgba(0,0,0,0.24);
  color: rgba(255, 239, 176, 0.92);
  font-weight: 950;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  text-align: center;
  opacity: 0;
  transition: opacity 160ms ease;
  pointer-events: none;
}
body.bags .bonus-bag.is-revealed .bonus-bag__amount{
  opacity: 1;
}

/* NOTE: Legacy “Grid Editor export” CSS blocks were removed.
   Layout is now driven by config.json (assets/grid/layout/uiLayout). */

@media (max-width: 520px){
  body.bags .bonus-bags{
    grid-template-columns: 1fr;
  }
  body.bags .bonus-bag__amount{
    top: 62%;
  }
}

/* Keyframes */
@keyframes bags-tile-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes bags-icon-pop {
  0% { transform: scale(0.78) rotate(-2deg); }
  55% { transform: scale(1.06) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes bags-speech-pop {
  0% { opacity: 0; transform: translateY(-6px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bags-bonus-enter {
  0% { opacity: 0; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bags-bag-drop {
  0% { opacity: 0; transform: translate3d(0, -46vh, 0) scale(0.92); }
  60% { opacity: 1; transform: translate3d(0, 6px, 0) scale(1.02); }
  78% { transform: translate3d(0, -8px, 0) scale(1.01); }
  100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes bags-bag-idle {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  40%  { transform: translate3d(0, -3px, 0) rotate(-0.4deg); }
  55%  { transform: translate3d(0, 0, 0) rotate(0.4deg); }
  70%  { transform: translate3d(0, -2px, 0) rotate(-0.2deg); }
  100% { transform: translate3d(0, 0, 0) rotate(0deg); }
}

@keyframes bags-bag-glow {
  0% { transform: translate3d(0, 0, 0) scale(1); filter: drop-shadow(0 0 10px rgba(255, 239, 176, 0.18)) drop-shadow(0 20px 26px rgba(0,0,0,0.40)); }
  55% { transform: translate3d(0, 0, 0) scale(1.03); filter: drop-shadow(0 0 26px rgba(255, 239, 176, 0.46)) drop-shadow(0 24px 30px rgba(0,0,0,0.42)); }
  100% { transform: translate3d(0, 0, 0) scale(1); filter: drop-shadow(0 0 16px rgba(255, 239, 176, 0.28)) drop-shadow(0 22px 28px rgba(0,0,0,0.40)); }
}

@keyframes bags-bag-reveal {
  0% { transform: scale(0.98) rotate(-1deg); }
  60% { transform: scale(1.05) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce){
  #grid.grid--3x3 .tile,
  #grid.grid--3x3 .tile__content,
  body.bags .bonus-bag{
    transition: none !important;
  }
  #grid.grid--3x3 .tile.is-revealed,
  #grid.grid--3x3 .tile.is-revealed .tile__icon,
  .speech-bubble.is-show,
  body.bags .bonus-overlay.is-enter .bonus-overlay__content,
  body.bags .bonus-bag.is-revealed img{
    animation: none !important;
  }
  body.bags .bonus-bag{
    opacity: 1 !important;
    transform: none !important;
  }
  body.bags .scratch-container{
    /* Keep config-driven layout, but remove parallax motion. */
    transform: translate(var(--aps-board-x, 0px), var(--aps-board-y, 0px)) scale(var(--aps-board-scale, 1)) rotate(var(--aps-board-rot, 0deg)) !important;
  }
}
