/* Background video */
.bg-desert-fortune{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  z-index: -5;
}

/* Give the mounted board a real layout box */
.boardWrap{
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 80px auto 0;
  min-height: 60vh;
  display: grid;
  place-items: center;
  pointer-events: none; /* frame only; grid re-enables */
}

@media (max-width: 768px){
  .boardWrap{
    margin-top: 40px;
    min-height: 50vh;
    max-width: 98vw;
  }
}

.boardContainer{
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}

/* Stack the shared header title + multiplier (Jungle-style) */
body[data-game="desert-fortune"] .ui-header .ui-game{
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.container-frame{
  position: relative;
  width: min(520px, 92vw);
  aspect-ratio: 1 / 1;   /* your frame is square */
  margin: 0 auto;
}
.frame--desert-fortune{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

:root{
  /* Grid overlay tuning inside the Desert Fortune frame.
     Defaults are equivalent to the previous inset values:
     inset: 26% 10% 24% 10%  => top 26, left 10, width 80, height 50 */
  --df-grid-top: 26%;
  --df-grid-left: 10%;
  --df-grid-width: 80%;
  --df-grid-height: 50%;
	--df-grid-gap: clamp(2px, 0.7vw, 8px);

  /* Config-driven pixel offsets (Studio Editor writes these fields):
     - layout.containerX/Y  => --container-x / --container-y
     - grid.x/y             => --grid-x / --grid-y
  */
  --container-x: 0px;
  --container-y: 0px;
  --grid-x: 0px;
  --grid-y: 0px;
}

/* Container offset */
.container-frame{
  transform: translate(var(--container-x), var(--container-y));
}

/* Grid overlays inside the frame */
#grid.grid--desert-fortune{
  position: absolute;
  top: calc(var(--grid-top, var(--df-grid-top)) + var(--grid-y));
  left: calc(var(--grid-left, var(--df-grid-left)) + var(--grid-x));
  width: var(--grid-width, var(--df-grid-width));
  height: var(--grid-height, var(--df-grid-height));

  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 5), 1fr);
  grid-template-rows: repeat(var(--grid-rows, 4), 1fr);

  row-gap: var(--grid-row-gap, var(--df-grid-gap));
  column-gap: var(--grid-col-gap, var(--df-grid-gap));

  pointer-events: auto;
}

/* Tiles */
#grid.grid--desert-fortune .tile{
  width: 100%;
  height: 100%;
	position: relative;
	box-sizing: border-box;
	padding: var(--tile-pad, clamp(6px, 1.6vw, 14px));
  box-sizing: border-box;
  background: url("../assets/tiles/desert-fortune-tile.svg") center/var(--tile-bg-scale, 115%) var(--tile-bg-scale, 115%) no-repeat;
  border-radius: 2px;
  overflow: hidden;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  will-change: transform;
}

#grid.grid--desert-fortune .tile:hover{
  transform: scale(1.03);
  box-shadow: 0 10px 22px rgba(0,0,0,.35);
}

#grid.grid--desert-fortune .tile__icon{
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84%;
  height: 84%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.5));
  opacity: 1;
  will-change: transform, opacity;
  z-index: 2;
}

/* Picked tile dim (keeps symbol fully opaque) */
#grid.grid--desert-fortune .tile.tile--picked::after{
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.28);
  pointer-events: none;
  z-index: 1;
}

/* Reveal flip (normal game) */
#grid.grid--desert-fortune .tile.tile--reveal-flip{
  animation: dfTileRevealFlip 320ms ease-in-out;
}

#grid.grid--desert-fortune .tile.tile--reveal-flip .tile__icon{
  animation: dfTileIconPop 320ms ease-out;
}

#grid.grid--desert-fortune .tile.tile--reveal-flip:hover{
  transform: none;
  box-shadow: none;
}

@keyframes dfTileRevealFlip{
  0%{ transform: rotateY(0deg) scale(1); }
  50%{ transform: rotateY(90deg) scale(1.03); }
  100%{ transform: rotateY(0deg) scale(1); }
}

@keyframes dfTileIconPop{
  0%{ transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
  100%{ transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Selection feedback */
.tile--selected{
  box-shadow: 0 0 0 4px #FFD700, 0 8px 20px rgba(0,0,0,0.4);
}
.tile--available{
  box-shadow: 0 0 0 2px #4caf50, 0 2px 8px rgba(0,0,0,0.18);
}

@media (max-width: 768px){
  /* Keep the game locked to the viewport on mobile (no page scroll). */
  html,
  body{
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

	/* Keep the board clear of the fixed shared header/actions on mobile */
	.ui-stage{
		padding-top: 110px;
    padding-bottom: calc(170px + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
	}

  /* Avoid extra document height that can re-enable scrolling. */
  .boardWrap{
    margin-top: 0;
    min-height: unset;
  }

	:root{
    /* Equivalent to previous mobile inset: 24% 6% 22% 6% => width 88, height 54 */
    --df-grid-top: 24%;
    --df-grid-left: 6%;
    --df-grid-width: 88%;
    --df-grid-height: 54%;
		--df-grid-gap: clamp(2px, 1vw, 6px);
	}
}

/* Grid Editor export (locked-in) */
#grid.grid--desert-fortune{
  --grid-top: 37%;
  --grid-left: 21.25%;
  --grid-width: 56.25%;
  --grid-height: 44.5%;
  --grid-row-gap: 0px;
  --grid-col-gap: 0px;
  --tile-bg-scale: 108%;
  --tile-pad: 17px;
}

/* =========================================================
   Sandstorm Bonus Overlay
========================================================= */

body.df-bonus-open{
  overflow: hidden;
  overscroll-behavior: none;
}

.dfBonus{
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  place-items: center;
  padding: 16px;
}

/* Respect the HTML `hidden` attribute (author CSS overrides UA defaults). */
.dfBonus[hidden]{
  display: none !important;
}

.dfBonus__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.dfBonus__panel{
  position: relative;
  width: min(860px, 92vw);
  max-height: min(86dvh, 860px);
  overflow: auto;
  border-radius: 18px;
  background: rgba(17, 11, 5, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  padding: 14px 14px 16px;
}

.dfBonus__close{
  position: absolute;
  top: 10px;
  right: 10px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.18);
  color: rgba(255,255,255,0.92);
  border-radius: 12px;
  padding: 8px 10px;
  line-height: 1;
}

.dfBonus__close:disabled{
  opacity: 0.45;
  cursor: not-allowed;
}

.dfBonus__title{
  margin: 0;
  padding-right: 44px;
  font-size: 16px;
  letter-spacing: .2px;
  color: rgba(255, 220, 120, 0.95);
}

.dfBonus__desc{
  margin: 6px 0 10px;
  color: rgba(255, 255, 255, 0.80);
}

.dfBonus__storm{
  width: min(520px, 92vw);
  margin: 6px auto 10px;
  display: grid;
  place-items: center;
}

.dfBonus__vortex{
  width: min(300px, 70vw);
  height: auto;
  filter: drop-shadow(0 18px 32px rgba(0,0,0,0.55));
  animation: dfBonusSpin 2.2s linear infinite, dfBonusPulse 2.6s ease-in-out infinite;
}

@keyframes dfBonusSpin{
  from{ transform: rotate(0deg); }
  to{ transform: rotate(360deg); }
}

@keyframes dfBonusPulse{
  0%, 100%{ filter: drop-shadow(0 18px 32px rgba(0,0,0,0.55)); transform: scale(1); }
  50%{ filter: drop-shadow(0 22px 40px rgba(0,0,0,0.60)); transform: scale(1.03); }
}

.dfBonus__spots{
  width: min(520px, 92vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2vw, 16px);
}

.dfBonus__spot{
  min-height: clamp(64px, 10vw, 92px);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(0,0,0,0.14);
  cursor: pointer;
  color: rgba(255, 239, 176, 0.92);
  font-weight: 950;
  font-size: 14px;
  letter-spacing: .2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.dfBonus__spot:hover{
  transform: translateY(-2px);
  border-color: rgba(255, 220, 120, 0.32);
  box-shadow: 0 0 0 2px rgba(255, 220, 120, 0.16), 0 18px 34px rgba(0,0,0,0.35);
}

.dfBonus__spot:focus-visible{
  outline: 2px solid rgba(255, 220, 120, 0.70);
  outline-offset: 3px;
}

.dfBonus__spot:disabled{
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.dfBonus__spot.is-revealed{
  background: rgba(255, 220, 120, 0.10);
  border-color: rgba(255, 220, 120, 0.35);
}

.dfBonus__summary{
  width: min(520px, 92vw);
  margin: 12px auto 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

.dfBonus__line{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: rgba(255, 255, 255, 0.86);
}

.dfBonus__line strong{
  color: rgba(255, 239, 176, 0.92);
}

@media (max-width: 520px){
  .dfBonus__panel{ padding: 12px; }
  .dfBonus__vortex{ width: min(240px, 70vw); }
}

/* =========================================================
   Vortex Sweep Bonus (new mechanic)
========================================================= */

body.df-vortex-mode .dfBonus__spots{
  display: none;
}

body.df-vortex-active #grid.grid--desert-fortune .tile:hover{
  transform: none;
  box-shadow: none;
}

.dfBonusGridOverlay{
  position: absolute;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  pointer-events: none;
  z-index: 6;
}

.dfBonusTile{
  position: relative;
  box-sizing: border-box;
  padding: var(--tile-pad, 17px);
  background: url("../assets/tiles/desert-fortune-tile.svg") center/108% 108% no-repeat;
  border-radius: 2px;
  overflow: hidden;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  will-change: transform;
}

.dfBonusTile__icon{
  position: absolute;
  left: 50%;
  top: 50%;
  width: 84%;
  height: 84%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.5));
  will-change: transform, opacity;
}

.dfBonusTile.is-flipping{
  animation: dfBonusTileFlip 260ms ease-in-out;
}

@keyframes dfBonusTileFlip{
  0%{ transform: rotateY(0deg) scale(1); }
  50%{ transform: rotateY(90deg) scale(1.03); }
  100%{ transform: rotateY(0deg) scale(1); }
}

.dfVortexRunner{
  position: absolute;
  top: 0;
  left: 0;
  z-index: 8;
  pointer-events: none;
  will-change: transform;
}

.dfVortexRunner__img{
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 18px 32px rgba(0,0,0,0.55));
  animation: dfVortexSpinCW 0.85s linear infinite;
}

@keyframes dfVortexSpinCW{
  from{ transform: rotate(0deg); }
  to{ transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce){
  .dfVortexRunner__img{ animation: none; }
  .dfBonusTile.is-flipping{ animation: none; }
  #grid.grid--desert-fortune .tile.tile--reveal-flip{ animation: none; }
  #grid.grid--desert-fortune .tile.tile--reveal-flip .tile__icon{ animation: none; }
}

.dfVortexHud{
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 9;
  width: min(480px, 92%);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(10, 6, 2, 0.68);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(10px);
  color: rgba(255,255,255,0.92);
  text-align: center;
  pointer-events: none;
}

.dfVortexHud__title{
  font-weight: 950;
  letter-spacing: 0.2px;
  color: rgba(255, 220, 120, 0.95);
}

.dfVortexHud__meta{
  margin-top: 4px;
  font-weight: 800;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
}

.dfStormPrelude{
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 10;
  width: min(520px, 92%);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(10, 6, 2, 0.62);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(10px);
  text-align: center;
  color: rgba(255, 220, 120, 0.95);
  font-weight: 900;
  letter-spacing: 0.3px;
  /* Arabic-style serif stack (English text). Falls back safely if unavailable. */
  font-family: "Amiri", "Noto Naskh Arabic", "Scheherazade New", "Segoe UI", serif;
}

@media (max-width: 520px){
  .dfStormPrelude{ top: 8px; padding: 10px 12px; }
}
