/* «أحجية النبات» (games/jigsaw-puzzle/). Ported from the Siwar standalone kids
   game; every rule is scoped to the game root. */

.kg-jigsaw-puzzle {
  /* The site's green scale and neutrals under the game's own names. */
  --jg-purple-deep: var(--green-900);
  --jg-purple-deep-2: var(--green-900);
  --jg-purple-mid: var(--green-600);
  --jg-purple-mid-2: var(--green-600);
  --jg-purple-light: var(--green-200);
  --jg-purple-soft: var(--green-50);
  --jg-bg: #fff;
  --jg-card-bg: #f3f4f6;
  --jg-card-bg-2: #f3f4f6;
  --jg-border: #d2d6db;
  --jg-border-soft: #d2d6db;
  --jg-text: #161616;
  --jg-text-mute: #6c737f;
  --jg-success: #1b8354;
  --jg-success-soft: #dff6e7;
  --jg-gold: #f2c94c;
  --jg-danger: #b42318;
  --jg-shadow-sm: none;
  --jg-shadow-md: none;
  --jg-shadow-lg: 0 12px 24px rgba(16, 24, 40, 0.12);
  --jg-radius-btn: 4px;
  --jg-radius-sm: 4px;
  --jg-radius-md: 8px;
  --jg-radius-lg: 16px;
  --jg-radius-xl: 16px;
  --jg-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: relative;
  display: block;
  width: 100%;
  /* As tall as the viewport allows (the game is scrolled to the top when play
     starts), so board, controls and tray show together. */
  height: clamp(280px, calc(100vh / var(--site-zoom, 1) - 24px), 760px);
  height: clamp(280px, calc(100svh / var(--site-zoom, 1) - 24px), 760px);
  scroll-margin-top: 12px;
  container-type: size;
  overflow: hidden;
  isolation: isolate;
  border-radius: var(--jg-radius-lg);
  box-shadow: 0 0 0 1px var(--jg-border-soft);
  background: var(--jg-bg);
  color: var(--jg-text);
  font-family: inherit;
  line-height: 1.5;
  direction: rtl;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.kg-jigsaw-puzzle *,
.kg-jigsaw-puzzle *::before,
.kg-jigsaw-puzzle *::after {
  box-sizing: border-box;
}

.kg-jigsaw-puzzle [hidden] {
  display: none !important;
}

.kg-jigsaw-puzzle :focus {
  outline: none;
}

.kg-jigsaw-puzzle :focus-visible {
  outline: 2px solid #161616;
  outline-offset: 2px;
}

.kg-jigsaw-puzzle h2:focus-visible {
  outline: none;
}

.kg-jigsaw-puzzle .jg-app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kg-jigsaw-puzzle .jg-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.35s var(--jg-ease), visibility 0s linear 0.35s;
}

.kg-jigsaw-puzzle .jg-screen.is-active {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.35s var(--jg-ease);
}

/* Content taller than the game (narrow phones, large text) scrolls instead of
   being cut; the column scrolls, so the decorative leaves never add overflow. */
.kg-jigsaw-puzzle .jg-screen:not([data-screen='game']) .jg-inner {
  height: 100%;
  overflow-y: auto;
}

.kg-jigsaw-puzzle .jg-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 900px;
  min-height: 100%;
  margin: 0 auto;
  padding: 20px;
}

.kg-jigsaw-puzzle [data-screen='game'] .jg-inner {
  height: 100%;
  padding: 16px;
}

.kg-jigsaw-puzzle .jg-leaf {
  position: absolute;
  z-index: 0;
  color: var(--jg-purple-mid);
  opacity: 0.06;
  pointer-events: none;
}

.kg-jigsaw-puzzle .jg-leaf--top {
  top: 20px;
  left: 20px;
  width: 100px;
  transform: rotate(15deg);
}

.kg-jigsaw-puzzle .jg-leaf--bottom {
  right: 20px;
  bottom: 20px;
  width: 120px;
  transform: rotate(-30deg);
}

/* ---------- Welcome ---------- */

.kg-jigsaw-puzzle .jg-welcome {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 8px;
  text-align: center;
}

.kg-jigsaw-puzzle .jg-welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 18px;
  border: 1px solid var(--jg-purple-light);
  border-radius: 999px;
  background: var(--jg-purple-soft);
  color: var(--green-700);
  font-size: 13px;
  font-weight: 500;
}

.kg-jigsaw-puzzle .jg-welcome-logo {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 130px;
  height: 130px;
  overflow: hidden;
  border-radius: var(--jg-radius-lg);
  background: var(--jg-purple-deep);
}

.kg-jigsaw-puzzle .jg-welcome-title {
  margin: 0;
  color: var(--jg-purple-deep);
  font-size: clamp(34px, 8vw, 52px);
  font-weight: 700;
  line-height: 1.2;
}

.kg-jigsaw-puzzle .jg-welcome-subtitle {
  max-width: 460px;
  margin: 8px 0 0;
  color: var(--jg-text-mute);
  font-size: clamp(15px, 3.5vw, 19px);
  line-height: 1.6;
}

.kg-jigsaw-puzzle .jg-welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

/* ---------- Buttons ---------- */

/* The flat site button (.btn in site.css) under the game's own class names. */
.kg-jigsaw-puzzle .jg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  margin: 0;
  padding: 8px 16px;
  border: 0;
  border-radius: var(--jg-radius-btn);
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  appearance: none;
  transition: background-color 0.15s ease;
}

.kg-jigsaw-puzzle .jg-btn-primary {
  background: var(--green-600);
  color: #fff;
}

.kg-jigsaw-puzzle .jg-btn-primary:hover {
  background: var(--green-700);
}

.kg-jigsaw-puzzle .jg-btn-primary:active {
  background: var(--green-900);
}

.kg-jigsaw-puzzle .jg-btn-secondary,
.kg-jigsaw-puzzle .jg-btn-tertiary {
  padding: 7px 15px;
  border: 1px solid var(--jg-border);
  background: #fff;
  color: var(--jg-text);
}

.kg-jigsaw-puzzle .jg-btn-secondary:hover,
.kg-jigsaw-puzzle .jg-btn-tertiary:hover {
  background: #f3f4f6;
}

.kg-jigsaw-puzzle .jg-btn-secondary:active,
.kg-jigsaw-puzzle .jg-btn-tertiary:active {
  background: #e5e7eb;
}

.kg-jigsaw-puzzle .jg-btn-tertiary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.kg-jigsaw-puzzle .jg-btn-block {
  width: 100%;
}

.kg-jigsaw-puzzle .jg-btn-icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-btn);
  background: #fff;
  color: var(--jg-text);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.kg-jigsaw-puzzle .jg-btn-icon:hover {
  background: #f3f4f6;
}

/* ---------- Levels ---------- */

.kg-jigsaw-puzzle .jg-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 4px;
}

.kg-jigsaw-puzzle .jg-header h2 {
  flex: 1;
  margin: 0;
  color: var(--jg-purple-deep);
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-levels-intro {
  margin-bottom: 24px;
  padding: 0 8px;
  text-align: center;
}

.kg-jigsaw-puzzle .jg-levels-intro h3 {
  margin: 0 0 8px;
  color: var(--jg-purple-deep);
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-levels-intro p {
  margin: 0;
  color: var(--jg-text-mute);
  font-size: 15px;
}

.kg-jigsaw-puzzle .jg-custom-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  padding: 10px 14px;
  border: 1px solid var(--jg-purple-light);
  border-radius: var(--jg-radius-md);
  background: var(--jg-purple-soft);
}

.kg-jigsaw-puzzle .jg-custom-banner-thumb {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-sm);
  background-color: #fff;
  background-position: center;
  background-size: cover;
}

.kg-jigsaw-puzzle .jg-custom-banner-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.kg-jigsaw-puzzle .jg-custom-banner-text strong {
  color: var(--jg-purple-deep);
  font-size: 14.5px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-custom-banner-text span {
  color: var(--jg-text-mute);
  font-size: 12.5px;
}

.kg-jigsaw-puzzle .jg-custom-banner-clear {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--jg-text-mute);
  cursor: pointer;
  appearance: none;
  transition: background 0.15s var(--jg-ease), color 0.15s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-custom-banner-clear:hover {
  background: var(--jg-purple-light);
  color: var(--jg-purple-deep);
}

.kg-jigsaw-puzzle .jg-level-cards {
  display: grid;
  gap: 14px;
}

.kg-jigsaw-puzzle .jg-level-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  margin: 0;
  padding: 19px;
  overflow: hidden;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-lg);
  background: var(--jg-bg);
  color: inherit;
  font-family: inherit;
  text-align: right;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.kg-jigsaw-puzzle .jg-level-card:hover {
  border-color: var(--jg-purple-mid);
  background: var(--jg-purple-soft);
}

.kg-jigsaw-puzzle .jg-level-card[data-locked='true'] {
  background: var(--jg-card-bg);
  cursor: not-allowed;
}

/* Locked cards are greyed by colour, not opacity, so their text keeps its contrast. */
.kg-jigsaw-puzzle .jg-level-card[data-locked='true'] .jg-level-icon {
  filter: grayscale(0.85);
}

.kg-jigsaw-puzzle .jg-level-card[data-locked='true'] .jg-level-title {
  color: var(--jg-text-mute);
}

.kg-jigsaw-puzzle .jg-level-card[data-locked='true']:hover {
  border-color: var(--jg-border);
  box-shadow: none;
  transform: none;
}

.kg-jigsaw-puzzle .jg-level-icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
}

.kg-jigsaw-puzzle [data-level='easy'] .jg-level-icon {
  background: var(--green-600);
}

.kg-jigsaw-puzzle [data-level='medium'] .jg-level-icon {
  background: var(--green-700);
}

.kg-jigsaw-puzzle [data-level='hard'] .jg-level-icon {
  background: var(--green-900);
}

.kg-jigsaw-puzzle .jg-level-info {
  display: block;
  flex: 1;
  min-width: 0;
}

.kg-jigsaw-puzzle .jg-level-title {
  display: block;
  margin: 0 0 4px;
  color: var(--jg-purple-deep);
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
}

.kg-jigsaw-puzzle .jg-level-desc {
  display: block;
  margin: 0 0 6px;
  color: var(--jg-text-mute);
  font-size: 13.5px;
  line-height: 1.5;
}

.kg-jigsaw-puzzle .jg-level-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--jg-purple-mid);
  font-size: 12.5px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-done {
  color: var(--green-700);
}

.kg-jigsaw-puzzle .jg-level-arrow {
  flex-shrink: 0;
  color: var(--jg-text-mute);
  transition: transform 0.2s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-level-card:hover .jg-level-arrow {
  color: var(--jg-purple-mid);
  transform: translateX(-4px);
}

.kg-jigsaw-puzzle .jg-lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--jg-border);
  border-radius: 999px;
  background: var(--jg-card-bg);
  color: var(--jg-text-mute);
  font-size: 12px;
  font-weight: 500;
}

/* A line lock, in place of the emoji the label used to start with. */
.kg-jigsaw-puzzle .jg-lock-badge::before {
  content: '';
  flex: none;
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- Game ---------- */

.kg-jigsaw-puzzle .jg-game-header {
  position: relative;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 16px;
  overflow: hidden;
  border-radius: var(--jg-radius-lg);
  background: var(--jg-purple-deep);
  color: #fff;
}

.kg-jigsaw-puzzle .jg-game-header :focus-visible {
  outline-color: #fff;
}

.kg-jigsaw-puzzle .jg-game-header .jg-btn-icon {
  z-index: 1;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.kg-jigsaw-puzzle .jg-game-header .jg-btn-icon:hover {
  background: rgba(255, 255, 255, 0.25);
}

.kg-jigsaw-puzzle .jg-game-title-block {
  z-index: 1;
  flex: 1;
  min-width: 0;
}

.kg-jigsaw-puzzle .jg-game-title-block h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.kg-jigsaw-puzzle .jg-game-level-tag {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 11.5px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-stars-display {
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 14px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-stars-display svg {
  width: 16px;
  height: 16px;
  fill: var(--jg-gold);
}

.kg-jigsaw-puzzle .jg-progress-bar-wrap {
  flex-shrink: 0;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-md);
  background: var(--jg-card-bg);
}

.kg-jigsaw-puzzle .jg-progress-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--jg-text-mute);
  font-size: 12.5px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-current {
  color: var(--jg-purple-deep);
  font-size: 14px;
}

.kg-jigsaw-puzzle .jg-progress-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--jg-border-soft);
}

.kg-jigsaw-puzzle .jg-progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--jg-purple-mid);
  transition: width 0.4s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-puzzle-area {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
}

/* Sized off the game box (never vh) so header, progress, controls and the
   smallest tray (371px together) still fit below it; the script then narrows
   one side to the image's aspect ratio. */
.kg-jigsaw-puzzle .jg-puzzle-board-wrap {
  position: relative;
  flex-shrink: 0;
  width: clamp(180px, min(100cqw - 32px, 100cqh - 371px), 520px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: var(--jg-radius-md);
  outline: 2px dashed var(--jg-border);
}

.kg-jigsaw-puzzle .jg-puzzle-board {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: var(--jg-radius-md);
  background: var(--jg-card-bg-2);
}

.kg-jigsaw-puzzle .jg-puzzle-slot {
  position: absolute;
  border: 1px dashed var(--jg-border);
  background: rgba(255, 255, 255, 0.4);
  transition: background 0.18s var(--jg-ease), border-color 0.18s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-puzzle-slot.jg-hover-correct {
  border-style: solid;
  border-color: var(--jg-success);
  background: var(--jg-success-soft);
  box-shadow: inset 0 0 0 2px var(--jg-success);
}

.kg-jigsaw-puzzle .jg-puzzle-slot.jg-hover-wrong {
  border-style: solid;
  border-color: var(--jg-danger);
  background: #fef3f2;
}

.kg-jigsaw-puzzle .jg-preview-image {
  position: absolute;
  inset: 0;
  z-index: 50;
  border-radius: var(--jg-radius-md);
  background-color: #fff;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-preview-image.is-shown {
  opacity: 1;
}

.kg-jigsaw-puzzle .jg-preview-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 51;
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(16, 70, 49, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
}

.kg-jigsaw-puzzle .jg-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
}

.kg-jigsaw-puzzle .jg-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--jg-purple-light);
  border-top-color: var(--jg-purple-mid);
  border-radius: 50%;
  animation: kg-jigsaw-spin 0.8s linear infinite;
}

@keyframes kg-jigsaw-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Controls and tray stack under the board; short landscape screens put them beside it. */
.kg-jigsaw-puzzle .jg-side {
  display: contents;
}

.kg-jigsaw-puzzle .jg-game-controls {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.kg-jigsaw-puzzle .jg-control-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  min-height: 32px;
  padding: 5px 11px;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-btn);
  background: var(--jg-bg);
  color: var(--jg-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.kg-jigsaw-puzzle .jg-control-btn:hover {
  background: #f3f4f6;
}

.kg-jigsaw-puzzle .jg-control-btn:active {
  background: #e5e7eb;
}

.kg-jigsaw-puzzle .jg-control-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}

.kg-jigsaw-puzzle .jg-sound-icon {
  display: inline-flex;
}

.kg-jigsaw-puzzle .jg-tray {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  max-width: min(75vmin, 420px);
  min-height: 130px;
  max-height: 240px;
  padding: 12px;
  border: 1px solid var(--jg-border);
  border-radius: var(--jg-radius-md);
  background: var(--jg-card-bg);
}

.kg-jigsaw-puzzle .jg-tray-label {
  position: absolute;
  top: -9px;
  right: 16px;
  padding: 0 8px;
  background: var(--jg-bg);
  color: var(--jg-text-mute);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 18px;
}

.kg-jigsaw-puzzle .jg-piece-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
}

.kg-jigsaw-puzzle .jg-clip-defs {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.kg-jigsaw-puzzle .jg-piece {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  background-color: #fff;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 4px rgba(16, 24, 40, 0.18));
  cursor: grab;
  touch-action: none;
  will-change: transform, width, height, filter;
}

.kg-jigsaw-puzzle .jg-piece:focus-visible {
  outline: none;
  filter: drop-shadow(0 0 3px #104631) drop-shadow(0 0 2px #104631);
}

.kg-jigsaw-puzzle .jg-piece-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.kg-jigsaw-puzzle .jg-piece.jg-placed .jg-piece-outline {
  display: none;
}

.kg-jigsaw-puzzle .jg-piece:active {
  cursor: grabbing;
}

.kg-jigsaw-puzzle .jg-piece.jg-dragging {
  z-index: 200;
  filter: drop-shadow(0 8px 16px rgba(16, 24, 40, 0.3));
  transition: none !important;
}

.kg-jigsaw-puzzle .jg-piece.jg-returning {
  transition: transform 0.35s var(--jg-ease), width 0.3s var(--jg-ease), height 0.3s var(--jg-ease),
    background-size 0.3s var(--jg-ease), background-position 0.3s var(--jg-ease),
    filter 0.3s var(--jg-ease);
}

/* Keyboard picks animate over the board instead of following a pointer. */
.kg-jigsaw-puzzle .jg-piece.jg-dragging.jg-returning {
  transition: transform 0.2s var(--jg-ease), width 0.2s var(--jg-ease), height 0.2s var(--jg-ease),
    background-size 0.2s var(--jg-ease), background-position 0.2s var(--jg-ease) !important;
}

.kg-jigsaw-puzzle .jg-piece.jg-placed {
  z-index: 5;
  filter: none;
  cursor: default;
  animation: kg-jigsaw-place-pop 0.45s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-piece.jg-snap-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
  animation: kg-jigsaw-snap-flash 0.55s var(--jg-ease) forwards;
}

.kg-jigsaw-puzzle .jg-piece.jg-shake {
  animation: kg-jigsaw-shake 0.4s var(--jg-ease);
}

@keyframes kg-jigsaw-place-pop {
  0% {
    filter: brightness(1.4);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes kg-jigsaw-snap-flash {
  0% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
  }
}

@keyframes kg-jigsaw-shake {
  0%,
  100% {
    translate: 0 0;
  }
  20% {
    translate: -8px 0;
  }
  40% {
    translate: 8px 0;
  }
  60% {
    translate: -6px 0;
  }
  80% {
    translate: 6px 0;
  }
}

.kg-jigsaw-puzzle .jg-sparkle {
  position: absolute;
  z-index: 300;
  width: 22px;
  height: 22px;
  pointer-events: none;
  animation: kg-jigsaw-sparkle-out 0.8s ease-out forwards;
}

@keyframes kg-jigsaw-sparkle-out {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.4) rotate(180deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.5) rotate(360deg);
    opacity: 0;
  }
}

/* ---------- Success ---------- */

.kg-jigsaw-puzzle .jg-success-content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 20px 12px;
  text-align: center;
}

.kg-jigsaw-puzzle .jg-success-icon {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--green-600);
}

.kg-jigsaw-puzzle .is-active .jg-success-icon {
  animation: kg-jigsaw-success-bounce 0.7s var(--jg-ease);
}

@keyframes kg-jigsaw-success-bounce {
  0% {
    transform: scale(0) rotate(-180deg);
  }
  60% {
    transform: scale(1.15) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

.kg-jigsaw-puzzle .jg-success-title {
  margin: 0;
  color: var(--jg-purple-deep);
  font-size: clamp(30px, 7vw, 42px);
  font-weight: 700;
  line-height: 1.2;
}

/* The photo gives up height first, so the name card and actions always fit. */
.kg-jigsaw-puzzle .jg-success-image-wrap {
  flex: 0 1 min(55vmin, 240px);
  min-height: 96px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 4px solid var(--jg-bg);
  border-radius: var(--jg-radius-lg);
  outline: 1px solid var(--jg-border);
  background-color: var(--jg-bg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: var(--jg-shadow-md);
}

.kg-jigsaw-puzzle .is-active .jg-success-image-wrap {
  animation: kg-jigsaw-zoom-in 0.5s var(--jg-ease) 0.2s both;
}

@keyframes kg-jigsaw-zoom-in {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.kg-jigsaw-puzzle .jg-plant-name-card {
  max-width: 420px;
  padding: 18px 24px;
  border: 1px solid var(--jg-purple-light);
  border-radius: var(--jg-radius-lg);
  background: var(--jg-purple-soft);
  text-align: center;
}

.kg-jigsaw-puzzle .is-active .jg-plant-name-card {
  animation: kg-jigsaw-fade-up 0.5s var(--jg-ease) 0.35s both;
}

@keyframes kg-jigsaw-fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kg-jigsaw-puzzle .jg-plant-name {
  margin: 0 0 4px;
  color: var(--jg-purple-deep);
  font-size: clamp(26px, 6vw, 34px);
  font-weight: 700;
  line-height: 1.3;
}

.kg-jigsaw-puzzle .jg-scientific-name {
  margin: 0 0 10px;
  color: var(--jg-text-mute);
  font-size: 13.5px;
  font-style: italic;
}

.kg-jigsaw-puzzle .jg-plant-fact {
  margin: 0;
  color: var(--jg-text);
  font-size: 14.5px;
  line-height: 1.7;
}

.kg-jigsaw-puzzle .jg-success-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.kg-jigsaw-puzzle .is-active .jg-success-actions {
  animation: kg-jigsaw-fade-up 0.5s var(--jg-ease) 0.5s both;
}

.kg-jigsaw-puzzle .jg-success-actions .jg-btn {
  flex: 1;
  min-width: 140px;
}

/* ---------- How-to dialog ---------- */

.kg-jigsaw-puzzle .jg-modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 24, 40, 0.55);
  opacity: 0;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.25s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-modal-overlay.is-shown {
  opacity: 1;
}

.kg-jigsaw-puzzle .jg-modal {
  width: 100%;
  max-width: 460px;
  max-height: 100%;
  padding: 28px 24px;
  overflow-y: auto;
  border-radius: var(--jg-radius-xl);
  background: var(--jg-bg);
  box-shadow: var(--jg-shadow-lg);
  transform: scale(0.92);
  transition: transform 0.3s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-modal:focus-visible {
  outline: none;
}

.kg-jigsaw-puzzle .jg-modal-overlay.is-shown .jg-modal {
  transform: scale(1);
}

.kg-jigsaw-puzzle .jg-modal h3 {
  margin: 0 0 16px;
  color: var(--jg-purple-deep);
  font-size: 24px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-modal-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.kg-jigsaw-puzzle .jg-modal-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--jg-border-soft);
  border-radius: var(--jg-radius-md);
  background: var(--jg-card-bg);
}

.kg-jigsaw-puzzle .jg-step-num {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--jg-purple-mid);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.kg-jigsaw-puzzle .jg-modal-steps p {
  margin: 0;
  color: var(--jg-text);
  font-size: 14.5px;
  line-height: 1.6;
}

/* ---------- Toast ---------- */

/* Top of the game, so it never covers the success actions or the piece tray. */
.kg-jigsaw-puzzle .jg-toast {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 2000;
  max-width: 90%;
  padding: 10px 16px;
  border-radius: var(--jg-radius-md);
  background: var(--jg-purple-deep);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--jg-shadow-lg);
  transform: translateX(-50%) translateY(-20px);
  transition: all 0.3s var(--jg-ease);
}

.kg-jigsaw-puzzle .jg-toast.is-shown {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 520px) {
  .kg-jigsaw-puzzle .jg-inner {
    padding: 14px;
  }

  .kg-jigsaw-puzzle [data-screen='game'] .jg-inner {
    padding: 12px;
  }

  .kg-jigsaw-puzzle .jg-welcome {
    gap: 22px;
    padding: 12px 4px;
  }

  .kg-jigsaw-puzzle .jg-welcome-logo {
    width: 100px;
    height: 100px;
    border-radius: var(--jg-radius-lg);
  }

  .kg-jigsaw-puzzle .jg-welcome-logo svg {
    width: 60px;
    height: 60px;
  }

  .kg-jigsaw-puzzle .jg-level-card {
    gap: 12px;
    padding: 14px;
  }

  .kg-jigsaw-puzzle .jg-level-icon {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .kg-jigsaw-puzzle .jg-level-title {
    font-size: 17px;
  }

  .kg-jigsaw-puzzle .jg-level-desc {
    font-size: 12.5px;
  }

  .kg-jigsaw-puzzle .jg-game-header {
    padding: 10px 12px;
  }

  .kg-jigsaw-puzzle .jg-game-title-block h2 {
    font-size: 15px;
  }

  .kg-jigsaw-puzzle .jg-stars-display {
    padding: 5px 10px;
    font-size: 13px;
  }

  .kg-jigsaw-puzzle .jg-progress-bar-wrap {
    margin-bottom: 10px;
    padding: 8px 12px;
  }

  .kg-jigsaw-puzzle .jg-puzzle-area {
    gap: 10px;
  }

  .kg-jigsaw-puzzle .jg-control-btn {
    padding: 8px 11px;
    font-size: 12.5px;
  }

  .kg-jigsaw-puzzle .jg-modal {
    padding: 22px 18px;
  }

  .kg-jigsaw-puzzle .jg-tray {
    min-height: 80px;
    padding: 10px;
  }
}

@media (max-height: 720px) {
  .kg-jigsaw-puzzle .jg-welcome {
    gap: 14px;
    padding-block: 4px;
  }

  .kg-jigsaw-puzzle .jg-welcome-subtitle {
    margin-top: 4px;
  }

  .kg-jigsaw-puzzle .jg-levels-intro {
    margin-bottom: 14px;
  }

  .kg-jigsaw-puzzle .jg-levels-intro h3 {
    margin-bottom: 4px;
  }

  .kg-jigsaw-puzzle .jg-header {
    margin-bottom: 8px;
  }

  .kg-jigsaw-puzzle .jg-level-cards {
    gap: 8px;
  }

  .kg-jigsaw-puzzle .jg-level-card {
    padding-block: 10px;
  }

  .kg-jigsaw-puzzle .jg-welcome-logo {
    width: 90px;
    height: 90px;
  }

}

@container (max-height: 700px) {
  .kg-jigsaw-puzzle .jg-success-content {
    gap: 12px;
    padding-block: 8px;
  }

  .kg-jigsaw-puzzle .jg-success-icon {
    width: 60px;
    height: 60px;
  }

  .kg-jigsaw-puzzle .jg-success-icon svg {
    width: 32px;
    height: 32px;
  }

  .kg-jigsaw-puzzle .jg-plant-name-card {
    padding: 12px 18px;
  }

  .kg-jigsaw-puzzle .jg-success-actions .jg-btn {
    padding-block: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kg-jigsaw-puzzle *,
  .kg-jigsaw-puzzle *::before,
  .kg-jigsaw-puzzle *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}

/* Short landscape screens (phones turned sideways): tray beside the board and
   compact screens, so a piece never has to travel past the viewport. */
@container (orientation: landscape) and (max-height: 560px) {
  .kg-jigsaw-puzzle .jg-inner,
  .kg-jigsaw-puzzle [data-screen='game'] .jg-inner {
    max-width: none;
    padding: 10px 16px;
  }

  .kg-jigsaw-puzzle .jg-leaf {
    display: none;
  }

  /* Top-aligned and without the badge, so «ابدأ اللعب» shows above the fold even
     with the page header above the game. */
  .kg-jigsaw-puzzle .jg-welcome {
    justify-content: flex-start;
    gap: 12px;
    padding: 4px;
  }

  .kg-jigsaw-puzzle .jg-welcome-badge,
  .kg-jigsaw-puzzle .jg-welcome-logo {
    display: none;
  }

  .kg-jigsaw-puzzle .jg-welcome-title {
    font-size: 32px;
  }

  .kg-jigsaw-puzzle .jg-welcome-subtitle {
    max-width: none;
    margin-top: 2px;
    font-size: 15px;
  }

  .kg-jigsaw-puzzle .jg-welcome-actions {
    flex-flow: row wrap;
    justify-content: center;
    max-width: 640px;
  }

  .kg-jigsaw-puzzle .jg-welcome-actions .jg-btn {
    flex: 1 1 0;
    min-width: 150px;
    padding: 12px 14px;
    font-size: 15px;
  }

  .kg-jigsaw-puzzle .jg-header {
    margin-bottom: 6px;
    padding: 0;
  }

  .kg-jigsaw-puzzle .jg-header h2 {
    font-size: 20px;
  }

  .kg-jigsaw-puzzle .jg-levels-intro {
    margin-bottom: 10px;
  }

  .kg-jigsaw-puzzle .jg-levels-intro h3 {
    font-size: 20px;
  }

  .kg-jigsaw-puzzle .jg-custom-banner {
    margin-bottom: 10px;
    padding: 6px 12px;
  }

  .kg-jigsaw-puzzle .jg-level-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .kg-jigsaw-puzzle .jg-level-card {
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-radius: var(--jg-radius-md);
  }

  .kg-jigsaw-puzzle .jg-level-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    font-size: 16px;
  }

  .kg-jigsaw-puzzle .jg-level-title {
    font-size: 16px;
  }

  .kg-jigsaw-puzzle .jg-level-desc {
    font-size: 12px;
  }

  .kg-jigsaw-puzzle .jg-level-arrow {
    display: none;
  }

  .kg-jigsaw-puzzle .jg-game-header {
    margin-bottom: 8px;
    padding: 6px 12px;
    border-radius: var(--jg-radius-md);
  }

  .kg-jigsaw-puzzle .jg-game-header .jg-btn-icon {
    width: 36px;
    height: 36px;
  }

  .kg-jigsaw-puzzle .jg-game-title-block {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .kg-jigsaw-puzzle .jg-game-title-block h2 {
    font-size: 15px;
  }

  .kg-jigsaw-puzzle .jg-game-level-tag {
    margin-top: 0;
  }

  .kg-jigsaw-puzzle .jg-progress-bar-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    padding: 6px 12px;
  }

  .kg-jigsaw-puzzle .jg-progress-bar-top {
    flex-shrink: 0;
    gap: 10px;
    margin-bottom: 0;
  }

  .kg-jigsaw-puzzle .jg-progress-bar {
    flex: 1;
  }

  .kg-jigsaw-puzzle .jg-puzzle-area {
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }

  .kg-jigsaw-puzzle .jg-puzzle-board-wrap {
    width: clamp(120px, min(100cqh - 124px, 45cqw), 520px);
    margin: 0;
  }

  .kg-jigsaw-puzzle .jg-side {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 14px;
    align-self: stretch;
    min-width: 0;
  }

  .kg-jigsaw-puzzle .jg-control-btn {
    padding: 6px 10px;
    font-size: 12.5px;
  }

  .kg-jigsaw-puzzle .jg-tray {
    flex: 1 1 auto;
    max-width: none;
    min-height: 0;
    max-height: none;
  }

  .kg-jigsaw-puzzle .jg-success-content {
    display: grid;
    grid-template-columns: auto minmax(0, 360px);
    align-content: center;
    justify-content: center;
    gap: 10px 24px;
    padding: 4px;
  }

  .kg-jigsaw-puzzle .jg-success-icon {
    display: none;
  }

  .kg-jigsaw-puzzle .jg-success-image-wrap {
    grid-row: 1 / span 3;
    align-self: center;
    width: clamp(96px, min(100cqh - 48px, 36cqw), 240px);
    min-height: 0;
  }

  .kg-jigsaw-puzzle .jg-success-title {
    font-size: 28px;
  }

  .kg-jigsaw-puzzle .jg-plant-name-card {
    padding: 10px 16px;
  }

  .kg-jigsaw-puzzle .jg-plant-name {
    font-size: 24px;
  }

  .kg-jigsaw-puzzle .jg-success-actions .jg-btn {
    padding: 10px 14px;
    font-size: 15px;
  }
}
