/* =============================================================
   ARCADE · 15-puzzle.css
   ============================================================= */

.game-page--puzzle {
  --accent: var(--violet);
  --accent-soft: rgba(139, 109, 255, 0.16);
  --board-w: 480px;
}

/* -------------------------------------------------------------
   Board
   ------------------------------------------------------------- */
.puzzle-board {
  --size: 4;
  --gap: 8px;
  position: relative;
  width: min(92vw, 480px);
  aspect-ratio: 1;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #12121a;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.puzzle-board__grid {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: var(--gap);
}

.puzzle-board__grid i {
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.028);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.022) inset;
}

.puzzle-board__tiles {
  position: absolute;
  inset: 10px;
}

/* -------------------------------------------------------------
   Tiles
   ------------------------------------------------------------- */
.tile {
  position: absolute;
  width: calc((100% - (var(--size) - 1) * var(--gap)) / var(--size));
  height: calc((100% - (var(--size) - 1) * var(--gap)) / var(--size));
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.13),
    rgba(255, 255, 255, 0.045) 55%,
    rgba(255, 255, 255, 0.02)
  );
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset,
    0 10px 24px -14px rgba(0, 0, 0, 0.85);
  font-family: var(--font-mono);
  font-size: clamp(1rem, 22cqw, 1.9rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  cursor: pointer;
  transition: translate 0.18s var(--ease), background 0.2s var(--ease),
    box-shadow 0.2s var(--ease), color 0.2s var(--ease),
    border-color 0.2s var(--ease), opacity 0.25s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.tile:hover {
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.19),
    rgba(255, 255, 255, 0.07) 55%,
    rgba(255, 255, 255, 0.03)
  );
}

.tile:active {
  transition-duration: 0.06s;
  filter: brightness(1.12);
}

/* placed correctly */
.tile.is-placed {
  border-color: rgba(139, 109, 255, 0.55);
  color: #cfc2ff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset,
    0 0 18px -6px rgba(139, 109, 255, 0.55),
    0 0 0 1px rgba(139, 109, 255, 0.25) inset;
}

.tile.is-hint {
  background: linear-gradient(
    165deg,
    rgba(139, 109, 255, 0.3),
    rgba(139, 109, 255, 0.12)
  );
  border-color: rgba(139, 109, 255, 0.6);
}

/* solved flash */
.tile.is-solved {
  animation: tileSolved 0.6s var(--ease-out);
}

@keyframes tileSolved {
  0% {
    box-shadow: 0 0 0 0 rgba(139, 109, 255, 0.7);
  }
  60% {
    box-shadow: 0 0 34px 4px rgba(139, 109, 255, 0.45);
  }
  100% {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset,
      0 0 18px -6px rgba(139, 109, 255, 0.55);
  }
}

/* slide-out (never used visually, kept for reduced-motion clarity) */
.tile.is-leaving {
  opacity: 0;
}

/* -------------------------------------------------------------
   Toolbar / hint
   ------------------------------------------------------------- */
.puzzle-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  max-width: 520px;
}

.puzzle-hint {
  font-size: 0.78rem;
  color: var(--dim);
}

.puzzle-hint b {
  color: var(--muted);
  font-weight: 600;
}

.puzzle-toolbar .btn {
  padding: 0.55rem 1.05rem;
  font-size: 0.82rem;
}

.diff--puzzle button {
  font-size: 0.74rem;
}

/* -------------------------------------------------------------
   Utilities
   ------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* -------------------------------------------------------------
   Responsive / motion
   ------------------------------------------------------------- */
@media (max-width: 560px) {
  .puzzle-board {
    padding: 7px;
    --gap: 6px;
  }

  .puzzle-board__grid,
  .puzzle-board__tiles {
    inset: 7px;
  }

  .puzzle-toolbar {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .puzzle-toolbar .btn {
    width: 100%;
  }

  .puzzle-hint {
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition: none;
  }

  .tile.is-solved {
    animation: none;
  }
}
