:root {
  --color-bg: #1b2430;
  --color-panel: #ffffff;
  --color-panel-border: #e2e5ea;
  --color-text: #1c2430;
  --color-muted: #6b7480;
  --color-primary: #2f8f5b;
  --color-primary-dark: #226b44;
  --color-danger: #c0392b;
  --color-accent: #3b6fd8;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
  /* الگوی افقیِ لوزی/ستاره یک‌بار (بدون کاشی‌شدن) کل صفحه را می‌پوشاند؛ یک
     لایه‌ی سفیدِ نیمه‌شفافِ کم‌رنگ رویش می‌نشیند تا رنگ‌های الگو پررنگ و
     زنده بمانند ولی کنتراست کلی صفحه هم خوانا بماند. */
  background-image: linear-gradient(rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.2)), url('assets/bg-pattern.jpg');
  background-repeat: no-repeat;
  background-size: cover, cover;
  background-position: center, center;
  background-attachment: fixed, fixed;
  background-color: var(--color-bg);
  color: var(--color-text);
  direction: rtl;
}

#game {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#game-header {
  position: relative;
  padding: 14px 24px;
  text-align: center;
}

#mute-btn {
  position: absolute;
  top: 10px;
  left: 14px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 3px 6px rgba(23, 38, 74, 0.3));
  transition: transform 150ms ease;
}

#mute-btn:hover {
  transform: scale(1.08);
}

#mute-btn:active {
  transform: scale(0.96);
}

#mute-btn-icon {
  width: 100%;
  height: 100%;
  display: block;
}

#game-header h1 {
  margin: 0 0 4px;
  color: #17264a;
  font-size: clamp(1.2rem, 2.4vw, 1.7rem);
}

#game-header p {
  margin: 0;
  color: #2c3b60;
  font-size: clamp(0.85rem, 1.5vw, 1rem);
}

#game-body {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 0 16px 16px;
  align-items: flex-start;
}

/* ===================== صحنه ===================== */

#scene-wrap {
  flex: 1 1 auto;
  min-width: 0;
}

#scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1810 / 868; /* نسبت ابعاد تصویر انبار، برای تطابق دقیق مختصات درصدی */
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  background-color: #4a4038;
  background-size: cover;
  background-position: center;
}

#hotspot-layer {
  position: absolute;
  inset: 0;
}

/* ---- شیء قابل‌کلیک عمومی ---- */
.hotspot {
  position: absolute;
  cursor: pointer;
}

/* قطعات درست (با مارکر قابل‌مشاهده) همیشه روی تله‌های نامرئی اولویت کلیک دارند،
   چون ممکن است محدوده‌ی مختصات‌شان با یک تله همپوشانی داشته باشد. */
.hotspot-correct {
  z-index: 2;
}

.hotspot-trap {
  z-index: 1;
}

.hotspot.disabled {
  cursor: not-allowed;
}

/* ---- اشیای دارای آرت واقعی (چه قطعه‌ی درست، چه تله) -------------------
   خودِ شیء از قبل در تصویر پس‌زمینه دیده می‌شود؛ .has-cutout فقط یک
   جای‌گیرنده‌ی بدون تعامل با اندازه‌ی کادر محاطیِ تنگ است، و داخلش فقط
   .hotspot-shape (نامرئی، با clip-path دقیقاً به شکل خود شیء بریده شده)
   برای تشخیص کلیک/هاور وجود دارد — بدون هیچ افکت بصری اضافه (گلو، جلو
   آمدن و…) روی خودِ شیء. */
.has-cutout {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hotspot-shape {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  cursor: pointer;
  background: transparent;
}

.has-cutout.disabled .hotspot-shape {
  cursor: not-allowed;
}

.has-cutout .badge {
  position: absolute;
  top: -10px;
  right: -10px;
}

/* ---- قطعات درستِ بدون آرت واقعی: مارکر دایره‌ای موقت ---- */
.placeholder-marker {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(47, 143, 91, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 2.2vw, 1.6rem);
  position: relative;
}

.placeholder-marker.selected .marker-circle,
.placeholder-marker.locked .marker-circle {
  background: rgba(47, 143, 91, 0.85);
}

.placeholder-marker.locked .marker-circle {
  border-color: #ffffff;
}

.marker-label {
  position: absolute;
  bottom: -1.6em;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: clamp(0.55rem, 1vw, 0.75rem);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 1px 8px;
  border-radius: 999px;
  pointer-events: none;
}

/* وقتی مارکر خیلی به لبه‌ی پایین صحنه نزدیک است، برچسب را به‌جای پایین،
   بالای دایره نشان بده تا زیر overflow:hidden صحنه بریده نشود. */
.placeholder-marker.label-above .marker-label {
  bottom: auto;
  top: -1.6em;
}

.hotspot.disabled .marker-circle {
  opacity: 0.4;
}

.badge {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.hotspot.locked .badge {
  background: var(--color-primary);
}

/* ===================== پنل کناری ===================== */

#sidebar {
  flex: 0 0 300px;
  max-width: 340px;
  width: 100%;
  /* کاغذ شطرنجی به‌عنوان بافت پس‌زمینه‌ی پنل، با یک لایه‌ی سفیدِ نیمه‌شفاف
     رویش تا متن‌ها همچنان واضح و خوانا بمانند. */
  background-image: linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)), url('assets/sidebar-pattern.jpg');
  background-repeat: repeat;
  background-size: auto, 160px auto;
  border: 1px solid var(--color-panel-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 110px);
  position: sticky;
  top: 12px;
}

#sidebar h2 {
  margin: 0;
  font-size: 1.05rem;
}

#counter {
  align-self: flex-start;
  font-weight: 700;
  color: var(--color-primary-dark);
  background: #eaf6ee;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
}

#selected-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 40px;
}

#empty-hint {
  color: var(--color-muted);
  font-size: 0.85rem;
  margin: 0;
}

.selected-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #cfe3f7;
  border: 1px solid #a9cceb;
}

.selected-row.locked {
  background: #b9e6c9;
  border-color: #7dcc9c;
}

.row-thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #b8d4ef;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.selected-row.locked .row-thumb {
  background: rgba(47, 143, 91, 0.38);
}

.row-name {
  flex: 1;
  font-size: 0.9rem;
}

.row-lock-icon {
  color: var(--color-primary-dark);
  font-size: 1rem;
}

.row-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-danger);
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
}

.row-remove:hover {
  background: rgba(192, 57, 43, 0.12);
}

#feedback-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feedback-item {
  background: #ffe9a8;
  border: 1px solid #e0bf5c;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 0;
}

#success-box {
  background: #b9e6c9;
  border: 1px solid #7dcc9c;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#success-box p {
  margin: 0;
  font-weight: 600;
  color: var(--color-primary-dark);
}

#next-stage-btn {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

#check-btn {
  margin-top: auto;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 150ms ease;
}

#check-btn:disabled {
  background: #c7ccd3;
  cursor: not-allowed;
}

#check-btn:not(:disabled):hover {
  background: var(--color-primary-dark);
}

.hidden {
  display: none !important;
}

/* ===================== توست ===================== */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2b2f38;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 50;
}

/* ===================== جشن موفقیت (کاغذرنگی و ستاره) ===================== */

#confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  animation-name: confetti-fly;
  animation-timing-function: cubic-bezier(0.15, 0.6, 0.4, 1);
  animation-fill-mode: forwards;
  will-change: transform, opacity;
}

.confetti-piece.paper {
  width: 10px;
  height: 15px;
  border-radius: 2px;
}

.confetti-piece.star {
  width: 16px;
  height: 16px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

@keyframes confetti-fly {
  0% {
    transform: translate(var(--sx), var(--sy)) rotate(0deg) scale(var(--scale));
    opacity: 1;
  }
  30% {
    transform: translate(var(--mx), var(--my)) rotate(calc(var(--rot) * 0.35)) scale(var(--scale));
    opacity: 1;
  }
  100% {
    transform: translate(var(--ex), var(--ey)) rotate(var(--rot)) scale(var(--scale));
    opacity: 0;
  }
}

/* ===================== ریسپانسیو ===================== */

@media (max-width: 860px) {
  #game-body {
    flex-direction: column;
  }

  /* در چیدمان ستونی، #game-body با align-items: flex-start (برای چیدمان
     ردیفی در دسکتاپ) دیگر عرض #scene-wrap را کشیده نمی‌کند؛ بدون این
     override، عرضش به‌جای پرشدنِ صحنه به اندازه‌ی محتوا جمع می‌شود. */
  #scene-wrap {
    width: 100%;
  }

  #sidebar {
    flex: 1 1 auto;
    max-width: none;
    position: static;
    max-height: none;
  }
}
