:root {
  --arena-size: 280px;
  --maze-cell-size: 35px;
  --puzzle-piece-size: 118px;
  --memory-card-size: 110px;
}

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

body {
  font-family: 'Segoe UI', sans-serif;
  background: #f0f4ff;
  color: #2c3e50;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden
}

header {
  flex-shrink: 0;
  background: linear-gradient(90deg, #8e44ad, #6c3483);
  color: #fff;
  width: 100%;
  text-align: center;
  padding: 0.8rem;
  box-shadow: 0 4px 15px rgba(142, 68, 173, .4);
  z-index: 10
}

h1 {
  font-size: 1.5rem
}

.prog-wrap {
  flex-shrink: 0;
  width: 100%;
  background: #ddd;
  height: 8px;
  z-index: 10
}

.prog-bar {
  height: 100%;
  background: linear-gradient(90deg, #27ae60, #2ecc71);
  width: 0%;
  transition: width .5s
}

#game {
  flex: 1;
  width: 95%;
  max-width: 680px;
  margin: 1rem auto;
  padding: 4px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth
}

.stage {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, .08);
  animation: fadeIn .5s;
  min-height: min-content
}

.stage.active {
  display: flex
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(15px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

h2 {
  color: #8e44ad;
  font-size: 1.8rem;
  margin-bottom: .5rem
}

p.desc {
  color: #666;
  font-size: 1rem;
  margin-bottom: 1rem;
  line-height: 1.6
}

.btn {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  border: none;
  padding: 12px 30px;
  font-size: 1.1rem;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(243, 156, 18, .35);
  margin: 6px;
  font-weight: bold;
  transition: transform .2s
}

.btn:hover {
  transform: scale(1.05)
}

.btn:disabled {
  background: #bbb;
  box-shadow: none;
  cursor: not-allowed;
  transform: none
}

.btn-green {
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  box-shadow: 0 4px 12px rgba(39, 174, 96, .35);
  display: none
}

.stage-img {
  width: 100%;
  max-width: 240px;
  max-height: 30vh;
  object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
  margin-bottom: 1rem;
  display: block
}

/* Landing Page */
.landing-img {
  width: 100%;
  max-width: 350px;
  border-radius: 15px;
  margin-bottom: 20px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.landing-title {
  color: #8e44ad;
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 2.2rem;
}
.btn-large {
  font-size: 1.5rem !important;
  padding: 15px 40px !important;
  border-radius: 30px !important;
  margin-top: 15px;
  display: inline-block !important;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.counter {
  font-size: 2.5rem;
  font-weight: bold;
  color: #8e44ad;
  border: 3px solid #8e44ad;
  border-radius: 50%;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px auto
}

#saai-c {
  font-size: 1.5rem;
  width: auto;
  height: auto;
  padding: 8px 20px;
  border-radius: 12px;
  min-width: 120px;
}

/* char select */
.char-row {
  display: flex;
  gap: 20px;
  margin-bottom: 1rem;
  justify-content: center
}

.char-card {
  border: 4px solid transparent;
  border-radius: 16px;
  padding: 12px;
  cursor: pointer;
  transition: all .3s;
  background: #fafafa
}

.char-card img {
  width: 120px;
  height: 150px;
  object-fit: cover;
  border-radius: 12px;
  display: block
}

.char-card h3 {
  color: #8e44ad;
  margin-top: 8px
}

.char-card.selected {
  border-color: #8e44ad;
  background: #f4ecf7;
  transform: scale(1.05)
}

/* TAWAF */
#tawaf-arena,
#tawaf-arena2 {
  width: var(--arena-size);
  height: var(--arena-size);
  border-radius: 50%;
  border: 4px dashed #bbb;
  position: relative;
  margin: 1rem auto;
  display: flex;
  align-items: center;
  justify-content: center
}

.kaaba-box {
  width: calc(var(--arena-size) * 0.28);
  height: calc(var(--arena-size) * 0.28);
  background: #1a1a2e;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 6px #f1c40f
}

.kaaba-box span {
  font-size: 2rem
}

/* Pilgrim starts at 3 o'clock on the orbit circle (radius=133, center=140,140) */
#tawaf-pilgrim {
  position: absolute;
  font-size: 2rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  top: calc(50% - 18px);
  left: calc(50% + 133px - 18px);
  transition: none
}

#tawaf2-pilgrim {
  position: absolute;
  font-size: 2rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  top: calc(50% - 18px);
  left: calc(50% + 133px - 18px);
  transition: none
}

.bg-pilgrim {
  position: absolute;
  font-size: 1.5rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0.5;
  z-index: 1
}

#tawaf-pilgrim,
#tawaf2-pilgrim {
  z-index: 10
}

/* SA'I MAZE */
#maze-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 1.5rem auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 5px;
}

#maze-container {
  display: grid;
  grid-template-columns: repeat(10, var(--maze-cell-size));
  grid-template-rows: repeat(7, var(--maze-cell-size));
  background: #f4ecf7;
  border: 4px solid #8e44ad;
  border-radius: 12px;
  direction: ltr;
  box-shadow: 0 5px 15px rgba(0, 0, 0, .1);
  position: relative;
  transition: all 0.3s ease;
  padding: 6px;
  width: fit-content;
  height: fit-content;
  overflow: hidden;
  box-sizing: border-box;
  order: 2;
  flex-shrink: 0;
}

#maze-container.maze-correct {
  border-color: #27ae60 !important;
  outline: 5px solid #27ae60;
  box-shadow: 0 0 20px rgba(39, 174, 96, 0.4);
}

#maze-container.maze-wrong {
  border-color: #e74c3c !important;
  outline: 5px solid #e74c3c;
  background-color: #fdeaea !important;
  box-shadow: 0 0 20px rgba(231, 76, 60, 0.4);
}

.maze-shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.maze-cell {
  width: var(--maze-cell-size);
  height: var(--maze-cell-size)
}

.maze-wall {
  background: #8e44ad;
  border-radius: 4px
}

#maze-player {
  position: absolute;
  width: var(--maze-cell-size);
  height: var(--maze-cell-size);
  transition: transform .2s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 10;
  top: 6px;
  left: 6px
}

.maze-hill {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: bold;
  border-radius: 8px;
  transition: all .3s;
  font-size: 0.9rem;
  flex-shrink: 0;
}

#maze-safa {
  background: #c0392b;
  box-shadow: 0 4px 0 #922b21;
  order: 3; /* RTL: left */
}

#maze-marwa {
  background: #2980b9;
  box-shadow: 0 4px 0 #1f618d;
  order: 1; /* RTL: right */
}

.maze-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 1.5rem;
  direction: ltr
}

.mc-row {
  display: flex;
  gap: 10px
}

.mc-btn {
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  box-shadow: 0 5px 0 #d68910;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: transform .1s, box-shadow .1s
}

.mc-btn:active {
  transform: translateY(5px);
  box-shadow: none
}

.mc-btn:disabled {
  background: #bbb;
  box-shadow: 0 5px 0 #999;
  cursor: not-allowed
}

/* TENT GAME */
.tent-row {
  display: flex;
  gap: 20px;
  margin: 1rem auto;
  justify-content: center
}

.tent-card {
  font-size: 5rem;
  cursor: pointer;
  border-radius: 16px;
  padding: 10px;
  border: 4px solid transparent;
  transition: all .3s
}

.tent-card.glow {
  border-color: #f39c12;
  background: #fff8e1;
  animation: glow-pulse .8s infinite alternate
}

@keyframes glow-pulse {
  from {
    box-shadow: 0 0 10px #f39c12
  }

  to {
    box-shadow: 0 0 25px #f39c12
  }
}

/* PUZZLE */
#puzzle-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: calc(var(--puzzle-piece-size) * 2 + 4px);
  margin: 1rem auto
}

.p-piece {
  width: var(--puzzle-piece-size);
  height: var(--puzzle-piece-size);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
  overflow: hidden;
  border: 3px solid #8e44ad;
  transition: transform .2s, border-color .2s
}

.p-piece.selected {
  border-color: #f1c40f;
  transform: scale(1.05);
  z-index: 2
}

/* MEMORY */
#memory-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--memory-card-size));
  gap: 12px;
  margin: 1rem auto;
  justify-content: center
}

.mem-card {
  width: var(--memory-card-size);
  height: var(--memory-card-size);
  border-radius: 14px;
  cursor: pointer;
  perspective: 600px
}

.mem-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .5s
}

.mem-card.flipped .mem-inner {
  transform: rotateY(180deg)
}

.mem-front,
.mem-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden
}

.mem-back {
  background: #8e44ad;
  transform: rotateY(180deg)
}

.mem-front {
  background: linear-gradient(135deg, #e8f4f8, #d6eaf8);
  border: 3px solid #bbb;
  font-size: 3.5rem
}

.mem-card.matched .mem-inner {
  transform: rotateY(180deg)
}

.mem-card.matched .mem-front {
  background: linear-gradient(135deg, #d4efdf, #a9dfbf);
  border-color: #27ae60
}

.p-piece.selected {
  border-color: #f1c40f;
  box-shadow: 0 0 15px #f1c40f;
  transform: scale(1.1)
}

.p-slot.filled {
  opacity: 1 !important;
  border: none
}

/* JAMARAT CLEANED */

/* overlay night */
.stage-img {
  max-width: 100%;
  width: auto;
  max-height: 30vh;
  border-radius: 20px;
  margin: 1rem auto;
  display: block;
  box-shadow: 0 8px 25px rgba(0, 0, 0, .1)
}

.char-row {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin: 1.5rem 0
}

.char-card {
  background: #f8f9fa;
  border: 3px solid #eee;
  border-radius: 20px;
  padding: 15px;
  cursor: pointer;
  transition: all .3s;
  width: 140px;
  text-align: center
}

.char-card img {
  width: 100%;
  height: 140px;
  border-radius: 16px;
  margin: 0 auto 10px;
  display: block;
  object-fit: contain;
  background: #fff;
  border: 3px solid #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .05)
}

.img-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto 1rem
}

.img-wrap img {
  max-width: 100%;
  width: auto;
  max-height: 30vh;
  border-radius: 16px;
  display: block;
  margin: 0 auto;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12)
}

.ritual-intro {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  min-height: 60vh;
  width: 100%;
  background-size: cover;
  background-position: center;
  color: #fff;
  overflow: hidden;
  border-radius: 20px
}

.ritual-intro::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.8));
  z-index: 1
}

.intro-body {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 100%
}

.ritual-intro h2 {
  margin: 0;
  color: #fff;
  font-size: 2.8rem;
  font-weight: bold;
  text-shadow: 0 3px 15px rgba(0, 0, 0, 0.5)
}

.ritual-intro .desc {
  color: rgba(255, 255, 255, 0.95);
  font-size: 1.4rem;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  font-weight: 500
}

.game-content {
  display: none;
  padding: 2rem;
  width: 100%
}

.btn-start {
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  font-size: 1.5rem;
  padding: 1.2rem 3rem;
  border-radius: 50px;
  box-shadow: 0 10px 25px rgba(230, 126, 34, 0.5);
  border: none;
  cursor: pointer;
  transition: all .3s;
  font-weight: bold
}

.btn-start:hover {
  transform: scale(1.08);
  box-shadow: 0 15px 30px rgba(230, 126, 34, 0.6)
}

.mem-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 1rem
}

.mem-row-label {
  font-size: 1.2rem;
  font-weight: bold;
  color: #8e44ad;
  margin-bottom: 0.5rem;
  text-align: right
}

/* Footer */
.main-footer {
  flex-shrink: 0;
  padding: 10px;
  text-align: center;
  color: #666;
  width: 100%;
  background: #fff;
  border-top: 2px solid #eee;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 100
}

.footer-desc {
  margin: 0 0 2px 0;
  font-size: 0.85rem
}

.footer-names {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-weight: bold;
  color: #8e44ad;
  font-size: 1rem
}

/* Responsive Overrides */
img {
  max-width: 100%;
  height: auto;
}

.game-content {
  padding: 1.5rem 1rem;
}

@media (max-width: 480px) {
  :root {
    --arena-size: 240px;
    --maze-cell-size: 20px;
    --puzzle-piece-size: 100px;
    --memory-card-size: 90px;
  }

  #maze-wrapper {
    margin: 0.5rem auto;
  }

  .maze-hill {
    width: 40px;
    height: 40px;
    font-size: 0.8rem;
  }

  .maze-controls {
    margin-top: 0.5rem;
  }

  .mc-btn {
    width: 45px;
    height: 45px;
    font-size: 1.3rem;
  }

  .char-row {
    gap: 10px;
  }

  .char-card {
    width: 130px;
    padding: 10px;
  }

  .mem-front,
  .mem-back {
    font-size: 2.5rem;
  }

  .tent-card {
    font-size: 3.5rem;
  }

  .btn {
    padding: 10px 20px;
    font-size: 1rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  .ritual-intro h2 {
    font-size: 2rem;
  }

  .ritual-intro .desc {
    font-size: 1.1rem;
  }
}

@media (max-width: 360px) {
  :root {
    --arena-size: 200px;
    --maze-cell-size: 18px;
    --puzzle-piece-size: 80px;
    --memory-card-size: 75px;
  }

  .maze-hill {
    width: 35px;
    height: 35px;
    font-size: 0.7rem;
  }

  .mc-btn {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .char-card {
    width: 110px;
  }

  .mem-front,
  .mem-back {
    font-size: 2rem;
  }

  .tent-card {
    font-size: 2.5rem;
  }

  h2 {
    font-size: 1.3rem;
  }
}